Magento 2 Get Coupon Code Programmatically Direct

$result = []; foreach ($collection as $order) $result[$order->getId()] = $order->getCouponCode();

try $order = $this->orderRepository->get($orderId); return $order->getCouponCode(); catch (\Exception $e) return null;

$this->orderRepository = $orderRepository; magento 2 get coupon code programmatically

$this->couponCollectionFactory = $couponCollectionFactory;

<?php namespace YourNamespace\YourModule\Model; use Magento\Sales\Api\OrderRepositoryInterface; $result = []

public function getAllCoupons(): array

public function getAppliedCouponForItem($itemId) foreach ($collection as $order) $result[$order-&gt

public function fromQuote(int $quoteId): ?string

Scroll to Top