I want to add Add condition in Coupon Code : If Email is subscriber@gmail.com
Please check attached screenshot:
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