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

#   Applying discount via plugin

##

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

Less More

- Posts: 9
- Thank you received: 0
-
-

11 years 2 months ago -  11 years 2 months ago [\#209739](#209739) by [designbuilder](/forum/user/36129-designbuilder "View designbuilder's Profile")  *[Applying discount via plugin](/forum/46-discount-coupon/878413-applying-discount-via-plugin#209739 "-- HikaShop version -- : 2.5.0  I have a plugin which processes a coupon against certain rules. I have a requirement that when product A is added to the cart, and the coupon matches a rule, product B is added to the cart. Product B should be discounted by 100%.  Using the function onAfterCouponCheck I add product B when required:  $product&#95;id = 'B'; $quantity = '10'; $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update($product&#95;id,$quantity);  Is there a way that I can apply a discount to product B when it is added to the cart so that it is a no cost addition to the cart.  Many thanks")* was created by *[designbuilder](/forum/user/36129-designbuilder "View designbuilder's Profile")*

-- HikaShop version -- : 2.5.0

I have a plugin which processes a coupon against certain rules. I have a requirement that when product A is added to the cart, and the coupon matches a rule, product B is added to the cart. Product B should be discounted by 100%.

Using the function onAfterCouponCheck I add product B when required:

$product_id = 'B';
$quantity = '10';
$cartClass = hikashop_get('class.cart');
$cartClass-&gt;update($product_id,$quantity);

Is there a way that I can apply a discount to product B when it is added to the cart so that it is a no cost addition to the cart.

Many thanks

Last edit: 11 years 2 months ago by [designbuilder](/forum/user/36129-designbuilder "View designbuilder's Profile"). Reason: Typo

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

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

11 years 2 months ago [\#209747](#209747) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Applying discount via plugin](/forum/46-discount-coupon/878413-applying-discount-via-plugin#209747 "-- HikaShop version -- : 2.5.0  I have a plugin which processes a coupon against certain rules. I have a requirement that when product A is added to the cart, and the coupon matches a rule, product B is added to the cart. Product B should be discounted by 100%.  Using the function onAfterCouponCheck I add product B when required:  $product&#95;id = 'B'; $quantity = '10'; $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update($product&#95;id,$quantity);  Is there a way that I can apply a discount to product B when it is added to the cart so that it is a no cost addition to the cart.  Many thanks")*

Hi,

There is no easy way to add a discounted product in the cart.
But you can override the product price or access to some cart elements (like "additional") using triggers.

[ www.hikashop.com/support/support/documen...mentation.html#other](http://www.hikashop.com/support/support/documentation/62-hikashop-developer-documentation.html#other)
[ www.hikashop.com/support/support/documen...fterCartProductsLoad](http://www.hikashop.com/support/support/documentation/62-hikashop-developer-documentation.html#onAfterCartProductsLoad)

The modification of the product price or the usage of "order additional" will allow you to create something near the discount.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

The following user(s) said Thank You: [designbuilder](/forum/user/36129-designbuilder "View designbuilder's Profile")

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

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

Less More

- Posts: 9
- Thank you received: 0
-
-

11 years 2 months ago [\#209861](#209861) by [designbuilder](/forum/user/36129-designbuilder "View designbuilder's Profile")  Replied by *[designbuilder](/forum/user/36129-designbuilder "View designbuilder's Profile")* on topic *[Applying discount via plugin](/forum/46-discount-coupon/878413-applying-discount-via-plugin#209861 "-- HikaShop version -- : 2.5.0  I have a plugin which processes a coupon against certain rules. I have a requirement that when product A is added to the cart, and the coupon matches a rule, product B is added to the cart. Product B should be discounted by 100%.  Using the function onAfterCouponCheck I add product B when required:  $product&#95;id = 'B'; $quantity = '10'; $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update($product&#95;id,$quantity);  Is there a way that I can apply a discount to product B when it is added to the cart so that it is a no cost addition to the cart.  Many thanks")*

Thank you for your response. I can achieve the discount by modifying the product price as you suggested. The unit price and total price for Product B are correct in the cart, however the subtotal is not correct. The Subtotal/Total pricing etc does not appear to be calculated using the modified prices.

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

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

11 years 2 months ago [\#209863](#209863) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Applying discount via plugin](/forum/46-discount-coupon/878413-applying-discount-via-plugin#209863 "-- HikaShop version -- : 2.5.0  I have a plugin which processes a coupon against certain rules. I have a requirement that when product A is added to the cart, and the coupon matches a rule, product B is added to the cart. Product B should be discounted by 100%.  Using the function onAfterCouponCheck I add product B when required:  $product&#95;id = 'B'; $quantity = '10'; $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update($product&#95;id,$quantity);  Is there a way that I can apply a discount to product B when it is added to the cart so that it is a no cost addition to the cart.  Many thanks")*

Hi,

If you modified the prices using the trigger "onAfterCartProductsLoad" that's logical.
That trigger is useful for the order additional but the cart total price is processed before the trigger is called.
(so if you want to change the product prices, you need to also recalculate the order full price ; but you might have an issue with the order creation...).

If not ; please indicate what you have done ; because you didn't share that information and if we do not know what you have done ; it will be more than difficult for us to help you.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQ2LWRpc2NvdW50LWNvdXBvbi84Nzg0MTMtYXBwbHlpbmctZGlzY291bnQtdmlhLXBsdWdpbj90bXBsPW1hcmtkb3du) 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.135 seconds

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

[](#top)
