Automatically apply coupons in cart (1 post)

    Posted 1 year ago #

    Hi there
    I am using woocommerce + Cheope to create a website but I am struggling to automatically apply 2 levels of discount in the shopping cart. I have found the following bit of code but it needs amending to meet my needs.....

    add_action( 'woocommerce_before_cart', 'apply_matched_coupons' );
    function apply_matched_coupons() {
        global $woocommerce;
        $coupon_code = '10percent'; // your coupon code here
        if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;
        if ( $woocommerce->cart->cart_contents_total >= 500 ) {
            $woocommerce->cart->add_discount( $coupon_code );

    I need a 10% discount coupon I have created to automatically apply if the cart totals more than £200 - and a 15% discount coupon to be applied if the cart totals more than £300 without the customer having to enter a code.

    I cannot post a link to the site at the moment as it is being developed on a temporary IP address but I will be able to allow access to anyone who can help me out. Please someone....anyone :-(

Topic Closed

This topic has been closed to new replies.

About this Topic