Coupon code is behaving strange
-
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]
- The topic ‘Coupon code is behaving strange’ is closed to new replies.