Created
May 14, 2021 05:45
-
-
Save wbcomdev/47fb3e2e2c8a64bcdad63afb4471ed72 to your computer and use it in GitHub Desktop.
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
| /** | |
| * Apply a coupon for minimum cart total. | |
| */ | |
| function wb_add_coupon_notice() { | |
| $cart_total = WC()->cart->get_subtotal(); | |
| $minimum_amount = 50; | |
| $currency_code = get_woocommerce_currency(); | |
| wc_clear_notices(); | |
| if ( $cart_total < $minimum_amount ) { | |
| WC()->cart->remove_coupon( 'COUPON' ); | |
| wc_print_notice( "Get 50% off if you spend more than $minimum_amount $currency_code!", 'notice' ); | |
| } else { | |
| WC()->cart->apply_coupon( 'COUPON' ); | |
| wc_print_notice( 'You just got 50% off your order!', 'notice' ); | |
| } | |
| wc_clear_notices(); | |
| } | |
| add_action( 'woocommerce_before_cart', 'wb_add_coupon_notice' ); | |
| add_action( 'woocommerce_before_checkout_form', 'wb_add_coupon_notice' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment