I want to change status order after payment for all products under category private
I tried this code but it works for all products, I need it works with products under category private only
`add_action( 'woocommerce_order_status_processing', 'processing_to_completed');
function processing_to_completed($order_id){
$order = new WC_Order($order_id);
$order->update_status('refunded');
}`
can any one help me?
add_action( 'woocommerce_order_status_processing', 'processing_to_completed');
function processing_to_completed($order_id){
$order = new WC_Order($order_id);
$order->update_status('refunded');
}
You have to check the items in your order and if any of the items is from specific category to change the order status.
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; } } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.