Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to check if coupons are valid or not magento 2

//normaly there should be only one rule that gets here since you can apply only one coupon code
$quote->setCouponCode('YOUR_COUPON')->collectTotals()->save(); 
$quoteCouponCode = $quote->getCouponCode();//get the applied coupon code from the quote
if ($quoteCouponCode){
  //$rule is valid and $rule->getCode() is a valid coupon code
}
//remove the coupon code from the quote if you want
$quote->setCouponCode('')->collectTotals()->save(); 
Source by magento.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #check #coupons #valid #magento
ADD COMMENT
Topic
Name
2+2 =