Untested code, but should do the trick
add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 );
function custom_order_status_by_cat( $order_id, $posted_data, $order ){
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if ( has_term( 'special-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e special-flowers
$order->update_status( 'wc-prepare' ); // your status here
break;
}
}
}
if you wanna do this for multiple cats
add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 );
function custom_order_status_by_cat( $order_id, $posted_data, $order ){
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if ( has_term( 'special-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e special-flowers
$order->update_status( 'wc-prepare' ); // your status here
break;
} else if ( has_term( 'cheap-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e cheap-flowers
$order->update_status( 'wc-prepare' ); // your status here
break;
}
}
}
or if you wanna get fancy you can check if they have items from multiple cats in their cart
add_action( 'woocommerce_checkout_order_processed', 'custom_order_status_by_cat', 10, 3 );
function custom_order_status_by_cat( $order_id, $posted_data, $order ){
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if ( has_term( 'special-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e special-flowers
if ( has_term( 'cheap-flowers', 'product_cat', $product_id ) ) { //enter in your cat i.e cheap-flowers
$order->update_status( 'wc-prepare' ); // your status here
break;
}
}
}
}
again, this is untested, but I believe it should work!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…