Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mcgregormedia/2d1b0222da84581ccf02 to your computer and use it in GitHub Desktop.
Save mcgregormedia/2d1b0222da84581ccf02 to your computer and use it in GitHub Desktop.
/**
* Show only free shipping option when available
*
* @param array $available_methods
*/
function show_only_free_shipping( $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 $available_methods
$available_methods = array();
$available_methods[] = $freeshipping;
endif;
return $available_methods;
}
add_filter( 'woocommerce_available_shipping_methods', 'show_only_free_shipping' , 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment