How to limit coupon code usage for guest user in Magento ?

By

March 29, 2017MagentoNo comments

Magento Shopping cart price rules provide the ability to limit the coupon usage for customers. But however, a Not Logged In User/Guest can use the same coupon code multiple times and get a discount. This seems to be a core bug and Magento doesn’t provide any restriction for guest users. In this article we will discuss on how to limit coupon code for guest user in Magento

The Common Problem of identifying the guest user:

Current Problem when it comes to restricting the coupon usage for Guest is we don’t know the identity of the guest unless he/she logs in to the Magento portal. To overcome this limitation we can shift the coupon box from “cart” page to “one-page” checkout and add a custom code to validate the coupon code usage for guest user. By moving the coupon box to “one-page” checkout section we can get the email id of the guest user in the billing address section.

Possible Solutions:

For placing the discount box in the checkout there are several free Magento extension available in Magento connect. https://www.magentocommerce.com/magento-connect/catalogsearch/result/?id=&s=7&pl=0&eb=0&hp=0&q=checkout+discount&t=1&p=1 we can use any one of them which suits our needs.For this example, i use the below extension which moves the coupon code to checkout step. https://www.magentocommerce.com/magento-connect/add-coupon-code-from-your-checkout-process.html
Next step is to add our custom module to restrict the guest coupon usage. Please find the sample code snippet of the observer class which will get executed whenever a sales rule is applied to the cart.
PHP

The complete module is available in the below GitHub link

https://github.com/rameshpushparaj/magento-restrict-guestcoupon

Leave a Reply