So, I have a custom function for when a order has been placed with the shipping method "Delivery", to change the status for better staff management.
It works fine, however ... if the customer clicks on the original link "WC Order confirmation link" to view the confirmation page of their original order, then that order automatically gets placed back into the Delivery status of the custom function.
Can someone please help me in ensuring if that the original confirmation page is reloaded, it does not change the status of the order?
add_action( 'woocommerce_thankyou', 'express_shipping_update_order_status', 10, 1 );
function express_shipping_update_order_status( $order_id ) {
if ( ! $order_id ) return;
$search = 'Delivery'; // The needle to search in the shipping method ID
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Get the WC_Order_Item_Shipping object data
foreach($order->get_shipping_methods() as $shipping_item ){
// When "delivery" method is used, we change the order to "new order for delivery" status
if( strpos( $shipping_item->get_method_title(), $search ) !== false){
$order->update_status('new-for-delivery');
break;
}
}
}