Types 排除Woocommerce中自动完成订单流程中的特定产品
我目前正在使用该代码自动完成订单,以便将新的WooCommerce预订添加到日历中(它们仅在标记为已完成时添加) 这对预订非常有效,但是,我想从自动完成中排除一些其他产品Types 排除Woocommerce中自动完成订单流程中的特定产品,types,woocommerce,product,orders,payment-method,Types,Woocommerce,Product,Orders,Payment Method,我目前正在使用该代码自动完成订单,以便将新的WooCommerce预订添加到日历中(它们仅在标记为已完成时添加) 这对预订非常有效,但是,我想从自动完成中排除一些其他产品 您知道这是否可行吗?迭代订单项比进行更轻松的SQL查询要复杂得多 下面是一个自定义条件函数,用于检查商业订单中的产品ID(返回true或false): 然后您将以这种方式使用它: add_action('woocommerce_thankyou', 'wc_auto_complete_order', 20, 1); funct
您知道这是否可行吗?迭代订单项比进行更轻松的SQL查询要复杂得多 下面是一个自定义条件函数,用于检查商业订单中的产品ID(返回true或false): 然后您将以这种方式使用它:
add_action('woocommerce_thankyou', 'wc_auto_complete_order', 20, 1);
function wc_auto_complete_order($order_id){
if (!$order_id) return;
// HERE define your Product Ids to exclude in the array
$product_ids = array( 37, 53 );
// Get an instance of the WC_Product object
$order = wc_get_order($order_id);
$found = order_has_products( $order_id, $product_ids );
if ( in_array( $order->get_payment_method(), array('cod', 'cheque', '') ) || $found ) {
return;
}
else {
$order->update_status('completed');
}
}
代码进入活动子主题(或活动主题)的function.php文件。测试和工作
您能否澄清“自动完成订单”、预订和日历的含义?你在哪里检查代码中的产品?嗯,我使用的代码没有,这就是我试图做的@LoicTheAztec的回答正是我所需要的!干杯
add_action('woocommerce_thankyou', 'wc_auto_complete_order', 20, 1);
function wc_auto_complete_order($order_id){
if (!$order_id) return;
// HERE define your Product Ids to exclude in the array
$product_ids = array( 37, 53 );
// Get an instance of the WC_Product object
$order = wc_get_order($order_id);
$found = order_has_products( $order_id, $product_ids );
if ( in_array( $order->get_payment_method(), array('cod', 'cheque', '') ) || $found ) {
return;
}
else {
$order->update_status('completed');
}
}