Created
November 15, 2017 20:18
-
-
Save mtruitt/25e52ef4be4671cf6f7237f6078bfe56 to your computer and use it in GitHub Desktop.
Auto applies Coupon w/ use of a different coupon.
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
| <?php | |
| /* | |
| * Auto applies coupon code based on another coupon code and removes all if either is removed | |
| */ | |
| function auto_apply_coupon() { | |
| $applied_coupon_code = 'Coupon manually applied goes here'; | |
| $coupon_code = 'coupon you want auto applied'; | |
| if ( WC()->cart->has_discount($applied_coupon_code) ) { | |
| WC()->cart->add_discount( $coupon_code ); | |
| WC()->cart->calculate_totals(); | |
| } elseif ( !WC()->cart->has_discount($applied_coupon_code) && WC()->cart->has_discount($coupon_code) ) { | |
| WC()->cart->remove_coupons(); | |
| WC()->cart->calculate_totals(); | |
| } | |
| }; | |
| add_action( 'woocommerce_before_cart_table','auto_apply_coupon' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment