Add Discount Coupon in Magento One Page Checkout (with and without coding)

Today, in this tutorial, I’ll assist you in the process of adding a discount coupon facility in checkout page of your ecommerce store to improve customer experience using coding and no coding. Now in short period of time you’d be able to add coupon code field to default Magento store and can start attracting customers amazingly.

There is no denying the fact that Magento is a robust platform. But, when it comes to customization, it can be really hard. However, customizations are inevitable for enhancing the performance of business. To sum up, you must customize your cart with or without developers to help your customers enjoy a perfect shopping on your store.

Also Read: Simplified Customer Checkout Guaranteed!

A common issue associated with the installation of Magento one page checkout on your store is that it won’t provide any option for customers to feed their coupon codes directly here. However, you can make it work for your customers through customization.

Down below here I’ve included a step-by-step guide using which it becomes easier to add a discount coupon field on the store of default Magento.

I have implemented discount coupon in “review” step of one page checkout and it has been displayed below.

Coupon Code in Default Magento


3-Step approach to add coupon code field with coding on default Magneto store

Step 1: Adding coupon action in one page controller

Open the onepage controller file. app/code/core/Mage/Checkout/controllers/OnepageController.php

Then go to Line # near to 593

function couponAction() {


$this->couponCode = (string) $this->getRequest()->getParam(‘coupon_code’);


Mage::getSingleton(‘checkout/cart’)->getQuote()->setCouponCode(strlen($this->couponCode) ?

$this->couponCode : ‘ ‘)->collectTotals()->save();

$result['goto_section'] = ‘review’;

$result['update_section'] = array( ‘name’ => ‘review’, ‘html’ => $this->_getReviewHtml() );



Step 2: Adding Js script to phtml file

Open file: app/design/frontend/base/default/template/checkout/onepage.phtml

Then go to Line # near to 63 and confirm that this is last line then copy and paste this code

<script type=”text/javascript”>


function updateCoupon(reqid) {

var reqid;

if(reqid == 2) {  $('coupon_code').setValue('');  }


method: 'post',

onComplete: payment.onComplete,

onSuccess: payment.onSave,

onFailure: checkout.ajaxFailure.bind(checkout),





Step 3: Adding form to phtml file

Open file: app/design/frontend/base/default/template/checkout/onepage/agreements.phtml

Then go to Line # near to 33 and confirm that this is first line then copy and paste this code

<?php $getCouponCode = Mage::getSingleton(‘checkout/cart’)->getQuote()->getCouponCode(); ?>

<form id=”discount-coupon-form” action=”” method=”post”>

<label for=”coupon_code”> <?php echo $this->__(‘Enter your coupon code if you have one.’) ?></label><br />

<input id=”coupon_code” name=”coupon_code” value=”<?php echo $getCouponCode; ?>”/>

<?php  if(strlen($getCouponCode)) { ?>

<button type=”button” onclick=”updateCoupon(2);” value=”<?php echo $this->__(‘Remove Coupon’)?>”><span><?php echo $this->__(‘Remove Coupon’) ?></span></button>

<?php } ?>

<button type=”button” onclick=”updateCoupon(1);” value=”<?php echo $this->__(‘Apply Coupon’)?>”><span><?php echo $this->__(‘Apply Coupon’) ?></span></button>


Adding coupon code option to one page checkout without coding

I know most of you would find it difficult to add coupon codes to default Magento store. Why to waste time when you’ve a best alternative to quickly add coupon code field on checkout page!

Now, it’s time to learn the easiest method to add coupon code option to your one page checkout page, of course, by deploying an extension. It just takes a few minutes to install Apptha’s one step checkout extension. As the extension carries the option of coupon code field already, it’ll appear in the checkout page in no time!!!

Looking forward to learn about more features of this product, check here:

Wish to try your hands on this product functionality, check here:

I hope the tutorial helped everyone reading this and it was beneficial. If you find it useful, try this and let us know your thoughts via comments.

Related posts

7 thoughts on “Add Discount Coupon in Magento One Page Checkout (with and without coding)

  1. Bryan Veloso

    Following the instructions you gave resulted to a blank white page. Maybe i did something wrong. Hmmmm..

  2. Demian

    Looking good, but I get an Syntax Phrase error on this line:
    $this->couponCode : ‘ ‘)->collectTotals()->save();

    missing something in the code?

  3. cynthia johnson

    You have shared a worthy information. When I was looking to add coupons to my store this information came handy.

    • ramanathan

      Hi Cynthia,

      Hope this information helped you for your ecommerce store. Also check out our ecommerce store related tips to get more insights.


  4. Tim Franklin


    I just implemented this script in my ecommerce store with one step check out. Promptly added the discount coupon codes in the default magento store with the code given. Now it works fine just replaced the quotations with ‘.

    • ramanathan

      Hi Tim,

      We are glad to know that you are using our product. Thanks for your review, if you need any extensions for your eCommerce store then keep visiting our store. We are updating with new sales boosting extensions for ecommerce stores with 20% off. Check and avail your offer now.

  5. ramanathan

    While copy pasting need to replace as above said to make sure the code completely works. We welcome your suggestion Brian, it will be helpful for other viewers too.

Leave a Reply

Your email address will not be published. Required fields are marked *



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">