0

I want to add Add condition in Coupon Code : If Email is subscriber@gmail.com

Please check attached screenshot: enter image description here

How to i'll do this programmatically. Please check my code everything is working fine only condition is not adding in coupon code.

/**
 * Retrieve the coupon code
 *
 * @return string
 */
protected function generateCouponCode()
{
    try {
        $couponData = [];
        $couponData['name'] = '10% Gift Voucher Newsletter Subscription ('.$this->getEmail().')';
        $couponData['is_active'] = '1';
        $couponData['simple_action'] = 'by_percent';
        $couponData['discount_amount'] = '10';
        $couponData['from_date'] = date('Y-m-d');
        $couponData['to_date'] = '2025-12-31 23:59:59';
        $couponData['uses_per_coupon'] = '1';
        $couponData['coupon_type'] = '2';
        $couponData['customer_group_ids'] = $this->getCustomerGroupIds();
        $couponData['website_ids'] = $this->getWebsiteIds();
        /** @var \Magento\SalesRule\Model\Rule $rule */
        $rule = $this->_getSalesRule();
        $couponCode = $rule->getCouponCodeGenerator()->setLength(7)->setAlphabet(
            'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
        )->generateCode().'';
        $couponData['coupon_code'] = $couponCode;
        $rule->loadPost($couponData);
        $rule->save();
        return $couponCode;
    } catch (\Exception $e) {
        return null;
    }
}

Kindly little help me on this.

Thanks

1 Answer 1

0

You can select Customer Group - ( General or any other), if you are providing any customer group to them. General is given by default to Registered Customers. You can assign any group to your customer and then apply your coupon on that specific Customer Group

In your Cart Price Rule - Do as follow:

enter image description here

4
  • This is not for only customers, subscriber should be anyone, even he is not registered on website. Jun 9 at 7:59
  • Then Select Not Logged In option too. It will be applied for anyone who is not registered. Jun 9 at 8:02
  • I think there is misunderstanding to understand my question or requirements. I am sending unique coupon to each subscriber. Now i want only that subscriber can use this coupon code. He cannot share this coupon code with anyone. coupon code should be validate against subscriber email. if email there is different email then he can't use. I hope now you understand my requirements. Jun 9 at 8:05
  • I assume that you created a Custom Module for sending coupon through email. Now, what you can do is, save that unique coupon with customer id. (in any custom table). Now when apply coupon check the coupon for the same customer id and perform coupon match. If yes then allow. Jun 9 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.