How to get shipping method instance_id?
-
Hello. I am struggling to get the selected shipping method’s instance_ID so that I can perform a conditional validation on the checkout page. I use “free_shipping:8” for those who want to use their own shipping account number and then validate that they filled in their own shipping account number in a custom checkout field. The problem is that I also use WooSubscriptions which seems to use “free_shipping” as well for virtual products and for some reasons my code below cannot differentiate. It sends all purchases through the validation code, including virtual subscriptions. I feel that I could get this to work if I could get a variable with the instance_id. I tried get_instance_id(); but with no luck. Thanks for any help!
add_action('woocommerce_checkout_process', 'custom_checkout_validation'); function custom_checkout_validation( ) { $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); $chosen_shipping = $chosen_methods[0]; if ( $chosen_shipping == 'free_shipping:8' && empty( $_POST['ship_account_field'] ) ){ wc_add_notice( 'Please provide your shipping account details below', 'error' ); } }
The topic ‘How to get shipping method instance_id?’ is closed to new replies.