Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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['free_shipping'] = $freeshipping;
endif;
return $available_methods;
}
@zepich
Copy link

zepich commented Oct 23, 2013

The line 22 is wrong. There key in the array must set:

$available_methods['free_shipping'] = $freeshipping;

Otherwise woocommerce do not use the correct shipping method.

@adefaveri
Copy link

adefaveri commented Nov 20, 2013

Great zepi! I agree!

@chirag-v
Copy link

chirag-v commented Nov 21, 2013

Zepi is right... We get an error saying "incorrect shipping method". Please correct it.

@woogist
Copy link
Author

woogist commented Dec 17, 2013

Thanks @zepi - we've updated the Gist now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment