我想在支付类别private下的所有产品后更改状态订单
我试过这段代码,但它适用于所有产品,我需要它只适用于类别私有的产品
' add_action('woocommerce_order_status_processing', 'processing_to_completed');
函数processing_to_completed (order_id美元){
$order = new WC_Order($order_id);
$order->update_status('refunded');
} '
有谁能帮我吗?add_action('woocommerce_order_status_processing', 'processing_to_completed');
函数processing_to_completed (order_id美元){
$order = new WC_Order($order_id);
$order->update_status('refunded');
}
您必须检查订单中的商品,如果有任何商品属于特定类别,则更改订单状态。
add_action( 'woocommerce_order_status_processing', 'processing_to_completed');
function processing_to_completed($order_id){
$order = new WC_Order($order_id);
foreach ( $order->get_items() as $item_id => $item ) {
$product_id = $item['product_id'];
// check if any of the products is in private category
if( has_term( array( 'private' ), 'product_cat', $product_id )) {
$order->update_status( 'refunded' ); // your status here
break;
}
}
}
add_action( 'woocommerce_thankyou', 'processing_to_completed');
function processing_to_completed($order_id){
if ( ! $order_id ){
return;
}
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if(has_term( 'under-category-private', 'product_cat', $product_id ) ) { //enter in your cat i.e under-category-private
$order->update_status( 'under-completed' ); // your own status here
break;
}
else{
$order->update_status( 'completed' ); // your other status here part from private category not in order.
break;
}
}
}