• Resolved bvk69varghese

    (@bvk69varghese)


    I have created the coupons through Woocommerce admin setting and applying the coupon using the below code.

    add_action(‘woocommerce_before_cart’, ‘bbloomer_apply_matched_coupons’);

    function bbloomer_apply_matched_coupons() {
    $current_user = wp_get_current_user();
    global $wpdb;
    $user_id = $current_user->ID;
    $subscription_amount = 0;
    /* SELECTING USER’s SUBSCRIPTION AMOUNT ($subscription_amount) FROM DB AND APPLYING THE COUPON LIKE THIS */
    $coupon_code = ”;
    if ($subscription_amount == 480){
    $coupon_code = ‘ABCDEFG’;
    WC()->cart->remove_coupons( ‘PQRSTUV’);
    }
    elseif ($subscription_amount == 1000 || $subscription_amount==700 || $subscription_amount==500){
    $coupon_code = ‘PQRSTUV’;
    WC()->cart->remove_coupons( ‘ABCDEFG’);
    }
    if ($coupon_code != ”)
    {
    if (WC()->cart->has_discount( $coupon_code ) ) return;

    WC()->cart->apply_coupon($coupon_code);
    }

    }

    This coupon is not adding when I add my subscriber product to cart. But its applying when I add another product from the store to the cart. If I remove this newly added product from cart the coupon discount is removing and I am getting a message like this “Sorry, it seems the coupon ‘PQRSTUV’ is invalid – it has now been removed from your order.” Not sure what is the issue here. Can you please help me on this.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Saif

    (@babylon1999)

    Hello @bvk69varghese,

    This coupon is not adding when I add my subscriber product to cart. But its applying when I add another product from the store to the cart. If I remove this newly added product from cart the coupon discount is removing and I am getting a message like this “Sorry, it seems the coupon ‘PQRSTUV’ is invalid – it has now been removed from your order.” Not sure what is the issue here. Can you please help me on this.

    Please note that debugging code is not within our scope of support here in the forums.

    Can you elaborate more on what you’re trying to achieve so we can guide you in the right direction?

    Also, please share a copy of your site’s System Status report. You can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support”.? Once you’ve done that, paste it here in your response.

    Look forward to hearing back from you.

Viewing 1 replies (of 1 total)
  • The topic ‘Coupon code is behaving strange’ is closed to new replies.