Using instance_id in WooCommerce 3.4+ to define the chosen shipping method
-
Since WooCommerce 3.4 the “shipping_method” and “instance_id” have been split, whereas before they were one colon separated value (ie table_rate:9). This is now causing some problems when I try to generate some custom meta data for the order based on the selected shipping rule.
Just to note, I’m using the WooCommerce Table Rate Plugin which is why my shipping_methods all display as “table_rate”.
This is the code that was working prior to WooCommerce 3.4
add_action('woocommerce_checkout_create_order', 'before_checkout_create_order', 20, 2); function before_checkout_create_order( $order, $data ) { if( $order->has_shipping_method('table_rate:9' ) { $order->update_meta_data( 'royal_mail_shipping_code', 'SD1' ); } if( $order->has_shipping_method('table_rate:8') ) { $order->update_meta_data( 'royal_mail_shipping_code', 'TPS48' ); } else $order->update_meta_data( 'royal_mail_shipping_code', 'No Value' ); }
After WooCommerce 3.4 the “shipping_method” returns “table_rate” rather than “table_rate:9” so I now need a way to check the order shipping “instance_id” instead, but I can’t find any documentation on how to do this.
The page I need help with: [log in to see the link]
- The topic ‘Using instance_id in WooCommerce 3.4+ to define the chosen shipping method’ is closed to new replies.