Magento 2 Get Coupon Code Programmatically May 2026

public function __construct(CollectionFactory $couponCollectionFactory)

Note: Magento does not store per‑item coupon codes; coupons apply at the entire quote/order level. Create a reusable service in your custom module. magento 2 get coupon code programmatically

<?php namespace YourNamespace\YourModule\Model; use Magento\Sales\Api\OrderRepositoryInterface; ?php namespace YourNamespace\YourModule\Model

use Magento\Quote\Model\QuoteFactory; public function getCouponCodeFromQuote(QuoteFactory $quoteFactory, $quoteId) magento 2 get coupon code programmatically

public function getAllCoupons(): array

public function getAppliedCouponForItem($itemId)