Created
August 26, 2020 19:37
-
-
Save munts/2941c00cd7f8b89c30042e88a2840354 to your computer and use it in GitHub Desktop.
Remove 'Free Shipping' option if user applies coupon code to WooCommerce cart. Ie. if using coupon, do not provide free shipping.
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
add_filter( 'woocommerce_shipping_packages', function( $packages ) { | |
$applied_coupons = WC()->session->get( 'applied_coupons', array() ); | |
if ( ! empty( $applied_coupons ) ) { | |
if ( in_array('promocode1', $applied_coupons) || | |
in_array('promocode2', $applied_coupons) | |
) { | |
$free_shipping_id = 'woodiscountfree'; | |
unset($packages[0]['rates'][$free_shipping_id]); | |
} | |
} | |
return $packages; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is assuming you have some logic somewhere that says something like if Cart total is more than XX, then offer free shipping. However, if they customer uses a coupon code that gets them say 20% off, then remove the free shipping option. Ie. Free Shipping is available when paying msrp.
In my snippet above, $free_shipping_id = 'woodiscountfree'
'woodiscountfree' is set using the WooDiscount plugin by FlyCart where we have a rule that Free Shipping is available if Cart is greater than $250.
This value can be found by inspecting element using dev tools.