Created
June 25, 2020 18:38
-
-
Save bolderelements/8b0b9c63f74855de62849f180cb07887 to your computer and use it in GitHub Desktop.
Hide One Table Rate Option When Another is Available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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