My current code even though has if statement doesn't follow it and still changes the status to "customstatus" of all the "on-hold" orders. Even though it should only change if the order contains the specific product id. This code also adds custom meta to the user. Not sure what I am doing wrong. Any help would be greatly appreciated.
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']=='on-hold') {
$items=$order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
if ($product_id!=="193007")
{
$current_user = wp_get_current_user();
$current_user_id = get_current_user_id();
$order->update_status( 'customstatus' );
update_user_meta( $current_user_id, 'custommeta', '2' );
}
}
}
}