Automatically update order status when shipment tracking is input in WooCommerce

Automatically update order status when shipment tracking is input in WooCommerce on child sites.

Snippet Type

Execute on Child Sites

Snippet

function update_order_status_when_shipment_tracking_input( $meta_id, $object_id, $meta_key, $meta_value ){
    if( $meta_key == '_wc_shipment_tracking_items' ){
        error_log('update_order_status_when_shipment_tracking_input');
        $order = wc_get_order( $object_id );
        if( $order ){
            $order->update_status( 'completed' );
        }
    }
}
add_action( 'update_postmeta', 'update_order_status_when_shipment_tracking_input', 10, 4 );

Hi Sebastian,
What is the prerequisites of this code? The order should have a field ‘_wc_shipment_tracking_items’? If yes is it OK to add as ACF field?

Thanks,
Ferenc

If you set the custom field (_wc_shipment_tracking_items) for shipment tracking on orders using say ACF or Pods then you could use the code.

Also applies if you are using the Shipment Tracking plugin from WooCommerce.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.