• Resolved vishakhanehe

    (@vishakhanehe)


    Hi,
    I have set up a coupon that should be restricted to an email address only. I am creating coupon from Admin itself, not from vendors.

    The problem is that it is applied irrespective of the email address entered while also working for logged-out users.

    Please let us know why it is happening?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Jahidul Hassan Mojumder

    (@jahidulhassan)

    Hi @vishakhanehe
    The coupon is not included in the free version of Dokan right now. This forum is meant to discuss only the functionalities that are available in the free version of Dokan.

    If you want to have any sort of assistance from our side about any pro feature of Dokan then please contact us via our support channel.

    Thanks.

    Thread Starter vishakhanehe

    (@vishakhanehe)

    Hi,
    I understand but as this is a very basic functionality with woocommerce and it was supposed to work.

    But unfortunately facing troubles.

    Hi @vishakhanehe,

    I’ve tested the issue in my local environment and found the problem in WooCommerce. By default, the email restriction doesn’t work for WooCommerce Coupons.

    In that case, you need to add the following code snippet at the bottom of the child theme’s functions.php file to make it work.

    function wc_coupon_email_restriction($result, $coupon) {
        if (null === WC()->cart) {
            return $result;
        }
    
        $user = wp_get_current_user();
        $restricted_emails = $coupon->get_email_restrictions();
    
        if (count($restricted_emails) > 0) {
            return WC()->cart->is_coupon_emails_allowed(
                [$user->user_email],
                $restricted_emails
            );
        } else {
            return $result;
        }
    }
    
    add_filter( 'woocommerce_coupon_is_valid', 'wc_coupon_email_restriction', 10, 2 );

    If the above solution doesn’t work, kindly contact WooCommerce Support for help. As the problem is with WooCommerce, they can help you with it.

    Thank you,

    Thread Starter vishakhanehe

    (@vishakhanehe)

    Hi @tanjiralmamun,
    I already tried this snippet.

    Hi @vishakhanehe,

    If you’re still having the problem, then kindly contact WooCommerce Support. Since there has a problem with WooCommerce, they can provide you a better solution.

    Thank you,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Coupon email restrictions not working’ is closed to new replies.