Skip to content

Instantly share code, notes, and snippets.

@bolderelements
Last active June 25, 2018 13:27
Show Gist options
  • Save bolderelements/91cd6c3625d6de1d34f7c4d03a7a454b to your computer and use it in GitHub Desktop.
Save bolderelements/91cd6c3625d6de1d34f7c4d03a7a454b to your computer and use it in GitHub Desktop.
Hide Free Shipping When Table Rate Option is Available
/**
* Hide all free shipping options when the given shipping option is available to choose
* Code snippets should be added to the functions.php file of your child theme
*
* @return array
*/
function hide_shipping_when_option_is_available( $rates, $package ) {
// set the desired option
$shipping_op = 'betrs_shipping:10-2';
if( array_key_exists( $shipping_op, $rates ) ) {
foreach( $rates as $key => $option ) {
if( $option->method_id == 'free_shipping' )
unset( $rates[ $key ] );
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_option_is_available', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment