[Skip to main content](#vessel-content)

#   How to add a coupon only for main price when using volume prices?

##

- **[oxido](/forum/user/29793-oxido "View oxido's Profile")**
- [![oxido's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/29793-oxido "View oxido's Profile") Topic Author
- [ Offline](/forum/user/29793-oxido)

Less More

- Posts: 285
- Thank you received: 42
-
-

2 years 1 month ago [\#363704](#363704) by [oxido](/forum/user/29793-oxido "View oxido's Profile")  *[How to add a coupon only for main price when using volume prices?](/forum/46-discount-coupon/908708-how-to-add-a-coupon-only-for-main-price-when-using-volume-prices#363704 "-- HikaShop version -- : 5.1.1 -- Joomla version -- : 5.1.4 -- PHP version -- : 8.2  Hello guys, Is there any way to applay this restriction now? So I have &quot;Product 1&quot; price 20$ If quantity is 5 price is 16$ If quantity is 10 price is 14$ And now, I want to create a discount or coupon that applay only for the main price. The discount / coupon has a -2$ flat. If I create a discount, not all volume prices should be cut &#91;strike&#93;20$&#91;/strike&#93; 18$ &#91;strike&#93;16$&#91;/strike&#93; 14$ not like this &#91;strike&#93;14&#91;/strike&#93; 12$ not like this =========================== &#91;strike&#93;20$&#91;/strike&#93; 18$ 16$ ok 14$ ok =========================== Is not ok to create the discount or the coupon with the limit on max qty 4, because that limitation it is applied to the entire cart, so if I have 5 different products, my discount is not gonna be applied anymore. Also, is no ok to create a discount for each product.  So you think that this can be made as a plugin, or a new feature in hikashop? If you think that it can be done as a plugin, can you show me the starting point? :D")* was created by *[oxido](/forum/user/29793-oxido "View oxido's Profile")*

-- HikaShop version -- : 5.1.1
-- Joomla version -- : 5.1.4
-- PHP version -- : 8.2

Hello guys,
Is there any way to applay this restriction now?
So I have "Product 1" price 20$
If quantity is 5 price is 16$
If quantity is 10 price is 14$
And now, I want to create a discount or coupon that applay only for the main price.
The discount / coupon has a -2$ flat.
If I create a discount, not all volume prices should be cut
[strike]20$[/strike] 18$
[strike]16$[/strike] 14$ not like this
[strike]14[/strike] 12$ not like this
===========================
[strike]20$[/strike] 18$
16$ ok
14$ ok
===========================
Is not ok to create the discount or the coupon with the limit on max qty 4, because that limitation it is applied to the entire cart, so if I have 5 different products, my discount is not gonna be applied anymore.
Also, is no ok to create a discount for each product.

So you think that this can be made as a plugin, or a new feature in hikashop?
If you think that it can be done as a plugin, can you show me the starting point? ![:D](/media/kunena/emoticons/1.png ":D")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi85MDg3MDgtaG93LXRvLWFkZC1hLWNvdXBvbi1vbmx5LWZvci1tYWluLXByaWNlLXdoZW4tdXNpbmctdm9sdW1lLXByaWNlcz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86556
- Thank you received: 14304
-
-

2 years 1 month ago [\#363705](#363705) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to add a coupon only for main price when using volume prices?](/forum/46-discount-coupon/908708-how-to-add-a-coupon-only-for-main-price-when-using-volume-prices#363705 "-- HikaShop version -- : 5.1.1 -- Joomla version -- : 5.1.4 -- PHP version -- : 8.2  Hello guys, Is there any way to applay this restriction now? So I have &quot;Product 1&quot; price 20$ If quantity is 5 price is 16$ If quantity is 10 price is 14$ And now, I want to create a discount or coupon that applay only for the main price. The discount / coupon has a -2$ flat. If I create a discount, not all volume prices should be cut &#91;strike&#93;20$&#91;/strike&#93; 18$ &#91;strike&#93;16$&#91;/strike&#93; 14$ not like this &#91;strike&#93;14&#91;/strike&#93; 12$ not like this =========================== &#91;strike&#93;20$&#91;/strike&#93; 18$ 16$ ok 14$ ok =========================== Is not ok to create the discount or the coupon with the limit on max qty 4, because that limitation it is applied to the entire cart, so if I have 5 different products, my discount is not gonna be applied anymore. Also, is no ok to create a discount for each product.  So you think that this can be made as a plugin, or a new feature in hikashop? If you think that it can be done as a plugin, can you show me the starting point? :D")*

Hi,

There is no option for that, but it can definitely be done as a plugin.

First, we have documentation about creating plugins for Joomla / HikaShop in general here:
[ www.hikashop.com/support/documentation/6...mentation.html#intro](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#intro)
If you're not familiar with this, I would recommend looking at this first.

I think the best is to implement the event onAfterCartProductsLoad of the cart API:
[ www.hikashop.com/support/documentation/6...fterCartProductsLoad](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#onAfterCartProductsLoad)
This event is triggered each time a cart is being loaded. You'll have most of the information about the cart in the one and only parameter of the event $cart, including an array of the product objects in $cart-&gt;products
So you can loop on that array in order to check which products are in the cart and the quantity of the product in the cart ( in the attribute cart_product_quantity ).
That way, you can calculate how much you want to give as a discount with whatever rules you need to apply.
Once you know the amount, you can add it to the cart: Code:

$discountAmount = 10; // suppose we want to add a discount of 10$ $additionalDiscount = new stdClass(); $additionalDiscount-&gt;name = 'The label of the discount'; $additionalDiscount-&gt;price_currency_id = 2; // 2 is the id of the currency for USD in System&gt;Currencies $additional-&gt;price_value = - $discountAmount; // since the amount is added to the cart, you want to make it negative so that it can reduce the total amount, and not increase it $additional-&gt;price_value_with_tax = - $discountAmount; // here you can add the amount with taxes. I just give the same amount for both discount amounts as this is just a simple example, but you'll likely want to calculate the taxes to be added or removed from your discount amount so that it matches with the taxes to apply to the cart $cart-&gt;additional['my_custom_discount'] = $additionalDiscount; // here the "fee" is added to the cart.

This mechanism of additional fees is used by several plugins, like the "multi coupon plugin", the "cart fee plugin" or the "global cart fee plugin" (this one is free, you can easily look at its code if you want) which are available in our marketplace.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi85MDg3MDgtaG93LXRvLWFkZC1hLWNvdXBvbi1vbmx5LWZvci1tYWluLXByaWNlLXdoZW4tdXNpbmctdm9sdW1lLXByaWNlcz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.046 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
