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' );
}
}
}
}
1条答案
按热度按时间mwg9r5ms1#
woocommerce_order_status_changed
has 4 parametersif ($product_id!="10")
says NOT equal, you also compare with a string and not with a numerical valueTry it this way