2 Get Coupon Code Programmatically __hot__ — Magento

$couponCode = 'MY_COUPON_CODE';

<?php namespace YourVendor\YourModule\Model; magento 2 get coupon code programmatically

cart(cart_id: "YOUR_CART_ID") applied_coupons code $couponCode = 'MY_COUPON_CODE'; &lt;

use Magento\Checkout\Model\Session as CheckoutSession; // ... Inside your class ... public function getCurrentAppliedCoupon() $quote = $this->checkoutSession->getQuote(); return $quote->getCouponCode(); // Returns the string code Use code with caution. $couponCode = 'MY_COUPON_CODE'

Note: Magento does not store per‑item coupon codes; coupons apply at the entire quote/order level.

$coupons = $this->getCouponsByRuleId(5); foreach ($coupons as $coupon) echo $coupon->getCode() . "\n";