Skip to content

Instantly share code, notes, and snippets.

@munts
Last active August 26, 2020 19:26
Show Gist options
  • Save munts/3b3539954773ddf99915052a0087138a to your computer and use it in GitHub Desktop.
Save munts/3b3539954773ddf99915052a0087138a to your computer and use it in GitHub Desktop.
Remove Flat Rate Shipping in WooCommerce if Customer Qualifies for Free Shipping with cart total greater than specific amount
/* Change shipping based on cart total and if they they qualify for free shipping */
add_filter( 'woocommerce_package_rates', 'hide_flat_rate_if_cart_total_is_greater_than_threshold', 5, 1 );
function hide_flat_rate_if_cart_total_is_greater_than_threshold( $rates ) {
$threshold1 = 249;
$amount = WC()->cart->cart_contents_total;
if ( $amount > $threshold1 ) {
unset( $rates['flat_rate:5'] );
}
return $rates;
}
@munts
Copy link
Author

munts commented Aug 26, 2020

$threshold1 = 249; //can be changed to any amount.

flat_rate:5 // flat_rate:# will vary from site to site, but this value can be found by using dev tools to find the input value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment