我正在尋找一個Woocommerce 操作掛鉤(或過濾器,我不確定),在發送新訂單電子郵件通知之前,我可以在其中更新送貨和賬單地址。
現在,我正在使用woocommerce_before_thankyou更新訂單元資料。
訂單已使用我要保存的正確地址保存,但電子郵件未顯示正確地址。
這是示例代碼,與我正在做的類似:
add_action( 'woocommerce_thankyou', 'checkout_save_user_meta');
function checkout_save_user_meta( $order_id ) {
$order = wc_get_order( $order_id );
$my_custom_address = 'My custom address';
update_post_meta( $order_id, '_billing_address_1', $my_custom_address );
update_post_meta( $order_id, '_shipping_address_1', $my_custom_address );
}
關于在這種情況下使用哪個鉤子有什么建議嗎?
uj5u.com熱心網友回復:
您可以使用woocommerce_checkout_create_order或woocommerce_checkout_update_order_meta動作掛鉤。
所以你會得到:
/**
* Action hook to adjust order before save.
*
* @since 3.0.0
*/
function action_woocommerce_checkout_create_order( $order, $data ) {
// Some value
$my_custom_address = 'My custom address';
// Update meta data
$order->update_meta_data( '_billing_address_1', $my_custom_address );
$order->update_meta_data( '_shipping_address_1', $my_custom_address );
}
add_action( 'woocommerce_checkout_create_order', 'action_woocommerce_checkout_create_order', 10, 2 );
或者
/**
* Action hook fired after an order is created used to add custom meta to the order.
*
* @since 3.0.0
*/
function action_woocommerce_checkout_update_order_meta( $order_id, $data ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Is a WC_Order
if ( is_a( $order, 'WC_Order' ) ) {
// Some value
$my_custom_address = 'My custom address';
// Update meta data
$order->update_meta_data( '_billing_address_1', $my_custom_address );
$order->update_meta_data( '_shipping_address_1', $my_custom_address );
// Save
$order->save();
}
}
add_action( 'woocommerce_checkout_update_order_meta', 'action_woocommerce_checkout_update_order_meta', 10, 2 );
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518320.html
