-
-
Save mikejolley/11171530 to your computer and use it in GitHub Desktop.
| // Hide ALL shipping options when free shipping is available | |
| add_filter( 'woocommerce_available_shipping_methods', 'hide_all_shipping_when_free_is_available' , 10, 1 ); | |
| /** | |
| * Hide ALL Shipping option when free shipping is available | |
| * | |
| * @param array $available_methods | |
| */ | |
| function hide_all_shipping_when_free_is_available( $available_methods ) { | |
| if( isset( $available_methods['free_shipping'] ) ) : | |
| // Get Free Shipping array into a new array | |
| $freeshipping = array(); | |
| $freeshipping = $available_methods['free_shipping']; | |
| // Empty the $available_methods array | |
| unset( $available_methods ); | |
| // Add Free Shipping back into $avaialble_methods | |
| $available_methods = array(); | |
| $available_methods[] = $freeshipping; | |
| endif; | |
| return $available_methods; | |
| } |
Make sure you read the instructions in the code iyfm! I commented out line 19 so that all other shipping methods would be hidden and it works great.
Hello Renegadesk,
Please help me!
I would like to hide the other shipping options, when the free shipping option is available.
Please write to me excatly, where and what code have to paste?
Thanks in advance,
Are you sure guys that this snippet will work again? I added to my function.php, but I have local_pickup, free_shipping and flat_rate that should be unset but it's not. I created a flat_rate just to make sure to have one, but I want to hide it. 99,99% of sells on my ecommerce have free_shipping, 0,01% have local_pickup. Flat_rate shouldn't be there, it's annoying for my customers. How can I fix it?
The example does not seem to work!
The example does not seem to work! Okay I had a caching problem with WooCommerce Transients
Works great! THANKS!
Worked great until the update to 2.6.
Did they changed the hooks with the new "shipping zones"-feature?
I'm just here to thank you. Graet job, thanks a lot.
Hi,
Trying to copy this code directly to our functions.php template file. But we get errors. Did I miss something?
Can someone maybe have a look at our functions.php?
Regards