Virtuemart coupons based on number of products

After looking around for quite sometime I was unable to find a Virtuemart plugin that would provide the functionality required.


To allow the admin user to create coupon codes within Virtuemart. Instead of specifying a percentage or total amount they would specify a number or products which would be free when using the coupon code. When the customer uses the coupon code they are allowed to choose any product on the website up to the total amount of products issued to the coupon. Regardless of the products price. The coupon code would also have the option for free shipping.

Extending Virtuemart

I can't release the code at this time but I can give you a good idea of the steps and a direction to take. Like always if you get stuck feel free to drop my an email.

  1. Extend the vm_ps_coupon class and override the update, add and process methods. Add and update should only require a change to the array that is sent to the DB. See here for more info on extending classes.
  2. Alter the enum in the database to allow for quantity as well as total and percent.
  3. Within your new update method handle the variation of quantity to do as you need.
  4. In the update method you can also set a flag for free shipping in a session variable.
  5. In templates/checkout edit list_shipping_methods.php. Simply check for the free shipping flag and load the free_shipping class. You can then call free_shipping->list_rates($vars);
  6. extend vm_ps_checkout, override the add method, call the parent add method and then check the result so you can delete the session variable for the free shipping.
  7. You can also add the coupon code to the order confirmation email. You need to override the email_receipt method in the ps_checkout class and store the coupon code in the information passed to the conformation_email.tpl.php file. Don't forget to display the values in the template file.

Warning Core changes

Finally you will need to make some changes in the admin HTML. Unfortunately I could not find a way to override this easily and since its only two small changes to the markup I just went ahead and hacked the core. If anyone knows of another way that would be great? I did see something online about using a Joomla hook and a System plugin but I'd rather keep it reliant on Virtuemart only.

In administrator/components/com_virtuemart/html/ edit coupon.coupon_form.php to show the new quantity radio button.

Then edit coupon.coupon_list.php to display the correct values. Currently it will only display percent and total.

Hope this helps someone in the future. If you need some assistance then post on here and I'll be happy to help.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.