Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bolderelements/8b0b9c63f74855de62849f180cb07887 to your computer and use it in GitHub Desktop.
Save bolderelements/8b0b9c63f74855de62849f180cb07887 to your computer and use it in GitHub Desktop.
Hide One Table Rate Option When Another is Available
/**
* Hide a specific Table Rate option 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 ) {
// setup the option IDs
$option_needed = 'betrs_shipping:8-1';
$option_removed = 'betrs_shipping:10-1';
// look for the needed option
if( array_key_exists( $option_needed, $rates ) ) {
if( array_key_exists( $option_removed, $rates ) ) {
unset( $rates[ $option_removed ] );
}
}
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