Imagine the scenario where we have 2 coupons, one (5off) that gives $5 discount to the total client order, as well as a coupon (10off) that gives $10 discount to the total client order.

When the user inserts any of the coupons in, we want the $10 off coupon to apply only if the total order value is over $50, otherwise, we want the $5 coupon to apply instead.

<?php /** * @snippet Add / Remove A Coupon Dynamically based on Cart Subtotal with WooCommerce * @sourcecode https://headless.wpharvest.com * @author Dragos Micu */ add_action( 'woocommerce_calculate_totals', 'wpharvest_apply_coupons' ); function wpharvest_apply_coupons($cart) { global $woocommerce; // Set your coupon codes $coupon10off = '10off'; $coupon5off = '5off'; // Get the cart subtotal $cart_subtotal = $cart->subtotal; // If cart subtotal is less than 50 add or remove coupons if ($cart_subtotal < 50) { if ( $woocommerce->cart->has_discount( $coupon10off ) ) { $cart->remove_coupon( $coupon10off ); $woocommerce->cart->add_discount( $coupon5off ); } } // If cart subtotal is greater 49 add or remove coupons if ($cart_subtotal > 49 ) { if ( $woocommerce->cart->has_discount( $coupon5off ) ) { $cart->remove_coupon( $coupon5off ); $woocommerce->cart->add_discount( $coupon10off ); } } }
Code language: PHP (php)

Did this coupon stop working, or need help with a different integration? Leave us a comment below and we’ll be more than happy to assist you!

Published by Dragos Micu

WooCommerce

Leave a Reply

Your email address will not be published. Required fields are marked *

managing high blood sugar with the right food for high sugar in the blood a comprehensive g 2661 is hemp gummies good for high blood pressure a comprehensive review 6182 movie pills vs ead56 insulin shots which is more effective for managing diabetes discussion how to a9ce2 lower blood sugar naturally the power of food and diet foods to help low blood sugar a comprehensive guide to regulating blood sugar levels will cashews raise blood sugar a comprehensive guide to nuts and diabetes management 2649 questions understanding healthy blood sugar levels before af3076f4 meals regulate your blood pressure with cbd gummies for blood pressure a natural approach to managing hyp reviews functional medicine strategies for pre diabetes preventing type 2 654c12ef diabetes naturally low blood sugar vs low blood pressure a comprehensive guide 9651 the importance of accurate blood sugar test strips for effective diabetes management 404798 food to lessen blood sugar a comprehensive guide to managing blood sugar levels 1883 effortless diabetes management the benefits of a blood sugar tracking app 6003 health master your fasting blood glucose natural strategies to achieve optimal blood sugar b51d3 levels questions metformin b802sugar the diabetes medication revolutionizing blood sugar management guides anti hyperglycemic drugs a guide to blood 87376b1e sugar management media intravenous af49lower therapy for diabetes management a comprehensive overview of key medications guides what are the most effective ways to 87376b1e lower high blood sugar will crestor raise blood sugar a comprehensive review 55384 the power of fruit that lowers blood sugar a comprehensive guide to managing diabetes 46229