I am trying to add coupon block in mini cart of magento.

But the coupon code block is displaying in the content section (also css changed!)


UPDATED: To display the coupon block in the minicart

 <referenceContainer name="minicart.addons">
        <block class="Magento\Checkout\Block\Cart\Coupon" name="checkout.cart.coupon">
                <argument name="template" xsi:type="string">Magento_Checkout::cart/coupon.phtml</argument>

In the xml it's unlikely that a reference to header-wrapper is the one to use. Something could be added in module-checkout/view/frontend/templates/cart/minicart.phtml.

I noticed <?php echo $block->getChildHtml('minicart.addons'); ?> in there, so maybe addons (like coupon) could be added from the back office.

If not then maybe you'll have to search in


or in module-checkout/view/frontend/web/js/discount-codes.js

Hope these are some helpful research track.

| improve this answer | |
  • oh cool buddy, i tried with referenceContainer name="minicart.addons" and it worked :D thanks for the tip, except the 'Apply Discount Code' link doesnt appear as one... like how it appears on the checkout page – Sushivam May 24 '17 at 6:02
  • If it is a display issue, then maybe it's due to some css in cart/coupon.phtml , that isn't destined to be in mini-cart area, conflicting there. maybe you can provide some more details, cool ! – medmek May 26 '17 at 9:20

You Can add this code in minicart.phtml

echo $this->getLayout()->createBlock('Magento\Checkout\Block\Cart\Coupon')->setTemplate('Magento_Checkout::cart/coupon.phtml')->toHtml();

But this has to be outside minicart-content-wrapper "div" else there will be css conflicts and Apply coupon code option won't work.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.