Coupon Code Programmatically: Magento 2 Get
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $quoteItem = $objectManager->create(\Magento\Quote\Model\Quote\Item::class)->load($itemId); $quote = $quoteItem->getQuote(); return $quote->getCouponCode(); // Same as quote-level coupon
<?php namespace YourNamespace\YourModule\Model; use Magento\SalesRule\Model\ResourceModel\Coupon\CollectionFactory; magento 2 get coupon code programmatically
$collection = $orderCollectionFactory->create() ->addFieldToFilter('entity_id', ['in' => $orderIds]) ->addFieldToSelect(['entity_id', 'coupon_code']); $quoteItem = $objectManager->
Often needed for order export, invoices, or customer history pages. $quote = $quoteItem->
return $quote->getCouponCode();



