mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/69662122/hide-shipping-methods-based-on-availability-of-other-shipping-methods-in-woocomm/69662514
12 lines
483 B
Text
12 lines
483 B
Text
function filter_woocommerce_package_rates( $rates, $package ) {
|
|
// Loop trough
|
|
foreach ( $rates as $rate_id => $rate ) {
|
|
// Checks if a value exists in an array, multiple can be added, separated by a comma
|
|
if ( in_array( $rate_id, array( 'local_pickup:1', 'free_shipping:2' ) ) ) {
|
|
unset( $rates['flat_rate:28'] );
|
|
}
|
|
}
|
|
|
|
return $rates;
|
|
}
|
|
add_filter( 'woocommerce_package_rates', 'filter_woocommerce_package_rates', 10, 2 );
|