Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created March 22, 2022 11:54
Show Gist options
  • Select an option

  • Save wpflames/aaeb31cc4b03edc84e544c8a9711309b to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/aaeb31cc4b03edc84e544c8a9711309b to your computer and use it in GitHub Desktop.
Unset Specific Shipping Methods if Free Shipping is Available
<?php
// =========================================================================
// Unset Specific Shipping Method if Free Shipping is Available
// =========================================================================
function unset_shipping_when_free_is_available_in_zone( $rates, $package ) {
// Only unset rates if free_shipping is available
if ( isset( $rates['free_shipping:8'] ) ) {
unset( $rates['flat_rate:1'] );
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'unset_shipping_when_free_is_available_in_zone', 9999, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment