【发布时间】:2019-08-06 14:57:03
【问题描述】:
有什么方法可以在 Woocommerce 上仅针对特定产品 ID 自动完成订单?
我使用代码on this thread 自动完成订单。
我还阅读了this thread,但它从自动完成中排除了产品 ID。而且我无法让它反过来工作。
由于我的商店中有 20 多种产品,而我只想在其中 2 种产品上使用自动完成功能,如果我可以指定要自动完成的订单 ID,那就太好了。
【问题讨论】:
标签: woocommerce
有什么方法可以在 Woocommerce 上仅针对特定产品 ID 自动完成订单?
我使用代码on this thread 自动完成订单。
我还阅读了this thread,但它从自动完成中排除了产品 ID。而且我无法让它反过来工作。
由于我的商店中有 20 多种产品,而我只想在其中 2 种产品上使用自动完成功能,如果我可以指定要自动完成的订单 ID,那就太好了。
【问题讨论】:
标签: woocommerce
这是一种自动完成特定产品 IDS 的已付款订单的方法:
add_action( 'woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 );
function wc_auto_complete_paid_order( $status, $order_id, $order ) {
// Below the targeted product Ids
$targeted_ids = array(37, 53);
// Loop through order line items
foreach( $order->get_items() as $item ) {
if ( in_array( $item->get_product_id(), $targeted_ids ) || in_array( $item->get_variation_id(), $targeted_ids ) ) {
return 'completed';
}
}
return $status;
}
代码进入活动子主题(或活动主题)的functions.php文件中。
【讨论】: