为外部送货服务购买订单时哪个 Woocommerce 挂钩
Which Woocommerce hook when order is purchased for an external delivery service
有时不调用函数woocommerce_thankyou,但有时工作正常。
我们的代码是:
add_action(‘woocommerce_thankyou’, ‘send_order_information_for_delivery’, 999, 1);
function send_order_information_for_delivery($order_id)
{
$order = wc_get_order($order_id);
$order_items = $order->get_items();
// … …
}
知道为什么有时不起作用吗?
该方法的主要objective是通过API.
获取采购订单及其项目的信息并发送到另一个数据库。
奇怪的是在某些命令中没有调用该方法。
相反,您可以尝试使用以下挂钩函数,在处理交付数据后,它只对定义的订单状态起作用一次。
add_action( 'woocommerce_order_status_changed', 'delivery_information_process', 20, 4 );
function delivery_information_process( $order_id, $old_status, $new_status, $order ){
// Define the order statuses to check
$statuses_to_check = array( 'on-hold', 'processing' );
// Only "On hold" order status and "Free Shipping" Shipping Method
if ( $order->get_meta( '_delivery_check', true ) && in_array( $new_status, $statuses_to_check ) )
{
// Getting all WC_emails objects
foreach($order->get_items() as $item_id => $item ){
$product = $item->get_product();
$sku = $product->get_sku();
}
## ==> Process delivery data step
// Once delivery information is send or processed ==> update '_delivery_check' to avoid repetitions
$order->update_meta_data( '_delivery_check', true );
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
有时不调用函数woocommerce_thankyou,但有时工作正常。
我们的代码是:
add_action(‘woocommerce_thankyou’, ‘send_order_information_for_delivery’, 999, 1);
function send_order_information_for_delivery($order_id)
{
$order = wc_get_order($order_id);
$order_items = $order->get_items();
// … …
}
知道为什么有时不起作用吗?
该方法的主要objective是通过API.
获取采购订单及其项目的信息并发送到另一个数据库。奇怪的是在某些命令中没有调用该方法。
相反,您可以尝试使用以下挂钩函数,在处理交付数据后,它只对定义的订单状态起作用一次。
add_action( 'woocommerce_order_status_changed', 'delivery_information_process', 20, 4 );
function delivery_information_process( $order_id, $old_status, $new_status, $order ){
// Define the order statuses to check
$statuses_to_check = array( 'on-hold', 'processing' );
// Only "On hold" order status and "Free Shipping" Shipping Method
if ( $order->get_meta( '_delivery_check', true ) && in_array( $new_status, $statuses_to_check ) )
{
// Getting all WC_emails objects
foreach($order->get_items() as $item_id => $item ){
$product = $item->get_product();
$sku = $product->get_sku();
}
## ==> Process delivery data step
// Once delivery information is send or processed ==> update '_delivery_check' to avoid repetitions
$order->update_meta_data( '_delivery_check', true );
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。