• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Hide shipping method in woocommerce if custom checkbox field is selected

Hardii

Well-known member
Babiato Lover
Trusted Uploader
Jul 1, 2022
143
515
93
Greetings,
So, i'm trying to hide a shipping method when a custom checkout checkbox field is checked. The custom checkbox field is "enabledropshipping" and the custom shipping method i need to hide is "shipping_method_0_flat_rate1".

function conditionaly_hide_shipping_method( $available_methods ) {
$post_data = urldecode($_POST['post_data']);
$post_data_arr = is_string($post_data) ? explode("&", $post_data) : array();
$field_value= '';
foreach ($post_data_arr as $value) {
$value_arr = is_string($value) ? explode("=", $value) : array();
if(isset($value_arr[0]) && $value_arr[0] === 'enabledropshipping'){
$field_value = isset($value_arr[1]) ? $value_arr[1] : '';
}
}
if(is_array($available_methods) && $field_value === 'shipping_method_0_flat_rate1'){
unset( $available_methods['shipping_method_0_flat_rate1'] );
}
return $available_methods;
}
add_filter( 'woocommerce_shipping_methods', 'conditionaly_hide_shipping_method' , 10, 1 );
 
Well thank you sir, i did not think of that :p

I've searched a lot, none of the things i've found worked. Neither with jquery neither with the above function.
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock