Created
October 14, 2020 22:05
-
-
Save juniorthiesen/8dfbeb3469b65a6136523aa750880276 to your computer and use it in GitHub Desktop.
hide shipping method ID
This file contains hidden or 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
add_filter( 'woocommerce_package_rates', 'hide_shipping_methods_based_on_item_count', 10, 2 ); | |
function hide_shipping_methods_based_on_item_count( $rates, $package ) { | |
// HERE the targeted shipping method ID (see the attribute "value" of the related shipping method input field) | |
$targeted_method_id = 'flat_rate:12'; // <== Replace with your DHL shipping method ID | |
// HERE the articles count threshold | |
$more_than = 15; | |
// Cart items count | |
$item_count = WC()->cart->get_cart_contents_count(); | |
if( WC()->cart->get_cart_contents_count() > $more_than ) { | |
foreach ( $rates as $rate_key => $rate ) { | |
if ( $rate->id != $targeted_method_id ) { | |
unset($rates[$rate_key]); | |
} | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment