I try to change a WooCommerce order status to "Processing" when the current status is "Approved" and the order includes a specific product ( id = 10).
I have attempted the code below but it is not working. I am quite new to php and would appreciate any guidance!
add_action('woocommerce_order_status_changed', 'ts_auto_complete_business_cards');
function ts_auto_complete_business_cards($order_id)
{
if ( ! $order_id ) {
return;
}
global $product;
$order = wc_get_order( $order_id );
if ($order->data['status'] == 'approved') {
$items=$order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if ($product_id!="10")
{
$order->update_status( 'completed' );
}
}
}
}