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

#   custom plugin that activates when coupon deleted

##

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

Less More

- Posts: 32
- Thank you received: 0
-
-

11 years 6 months ago [\#199653](#199653) by [diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")  *[custom plugin that activates when coupon deleted](/forum/25-install-update/876573-custom-plugin-that-activates-when-coupon-deleted#199653 "-- HikaShop version -- : 2.3.1 -- Joomla version -- : 2.5.2 -- PHP version -- : 5  Hi,  I am trying to write a plugin that executes when a coupon is deleted from the frontend of the website by a customer. What i need it to do, is remove a particular item from the basket when a certain coupon is deleted. I have added what i have coded so far below. I cannot even get an exit() statement alone to execute in the onAfterDiscountDelete(&amp;$elements) function. The onAfterDiscountDelete(&amp;$elements) function doesn't appear to execute even when a coupon is deleted from the frontend of the website. I have written numerous plugins for hikashop now and they have all worked so far (except for this one)...  So i need to know:  Why my plugin is not executing; What code i need to delete an item from the basket;  My plugin is installed and it is published so that is not the issue here. I have stored my plugin in:-  /plugins/hikashop/discount/  and that folder contains the following files:- discount.php discount.xml index.html  The code below is contained within:-  /plugins/hikashop/discount/discount.php  Code: loadFullCart();   $numberOfProductsInCart = sizeof($cart-&gt;products);   for($i=0; $iproducts&#91;$i&#93; == 120) {   //I need some code to remove this item from the basket - but what code will achieve that?   }   }   }  }  ?&gt;  Thanks in advance guys!")* was created by *[diesel1984](/forum/user/30999-diesel1984 "View diesel1984's Profile")*

-- HikaShop version -- : 2.3.1
-- Joomla version -- : 2.5.2
-- PHP version -- : 5

Hi,

I am trying to write a plugin that executes when a coupon is deleted from the frontend of the website by a customer. What i need it to do, is remove a particular item from the basket when a certain coupon is deleted. I have added what i have coded so far below. I cannot even get an exit() statement alone to execute in the onAfterDiscountDelete(&amp;$elements) function. The onAfterDiscountDelete(&amp;$elements) function doesn't appear to execute even when a coupon is deleted from the frontend of the website. I have written numerous plugins for hikashop now and they have all worked so far (except for this one)...

So i need to know:

Why my plugin is not executing;
What code i need to delete an item from the basket;

My plugin is installed and it is published so that is not the issue here. I have stored my plugin in:-

/plugins/hikashop/discount/

and that folder contains the following files:-
discount.php
discount.xml
index.html

The code below is contained within:-

/plugins/hikashop/discount/discount.php

Code:

&lt;?php defined('_JEXEC') or die('Restricted access'); ?&gt;&lt;?php class plgHikashopDiscount extends JPlugin { function plgHikashopDiscount(&amp;$subject, $config) { parent::__construct($subject, $config); } function onAfterDiscountDelete(&amp;$elements) { if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; } $cartClass = hikashop_get('class.cart'); $cart = $cartClass-&gt;loadFullCart(); $numberOfProductsInCart = sizeof($cart-&gt;products); for($i=0; $i&lt;$numberOfProductsInCart; $i++) { if($cart-&gt;products[$i] == 120) { //I need some code to remove this item from the basket - but what code will achieve that? } } } } ?&gt;

Thanks in advance guys!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzg3NjU3My1jdXN0b20tcGx1Z2luLXRoYXQtYWN0aXZhdGVzLXdoZW4tY291cG9uLWRlbGV0ZWQ/dG1wbD1tYXJrZG93bg==) 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: 4077
-
- [](http://obsi.dev)
-

11 years 6 months ago [\#199663](#199663) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[custom plugin that activates when coupon deleted](/forum/25-install-update/876573-custom-plugin-that-activates-when-coupon-deleted#199663 "-- HikaShop version -- : 2.3.1 -- Joomla version -- : 2.5.2 -- PHP version -- : 5  Hi,  I am trying to write a plugin that executes when a coupon is deleted from the frontend of the website by a customer. What i need it to do, is remove a particular item from the basket when a certain coupon is deleted. I have added what i have coded so far below. I cannot even get an exit() statement alone to execute in the onAfterDiscountDelete(&amp;$elements) function. The onAfterDiscountDelete(&amp;$elements) function doesn't appear to execute even when a coupon is deleted from the frontend of the website. I have written numerous plugins for hikashop now and they have all worked so far (except for this one)...  So i need to know:  Why my plugin is not executing; What code i need to delete an item from the basket;  My plugin is installed and it is published so that is not the issue here. I have stored my plugin in:-  /plugins/hikashop/discount/  and that folder contains the following files:- discount.php discount.xml index.html  The code below is contained within:-  /plugins/hikashop/discount/discount.php  Code: loadFullCart();   $numberOfProductsInCart = sizeof($cart-&gt;products);   for($i=0; $iproducts&#91;$i&#93; == 120) {   //I need some code to remove this item from the basket - but what code will achieve that?   }   }   }  }  ?&gt;  Thanks in advance guys!")*

Hi,

[ www.hikashop.com/support/support/documen...tation.html#discount](http://www.hikashop.com/support/support/documentation/62-hikashop-developer-documentation.html#discount)

> onAfterDiscountDelete( &amp; $elements )
> This function will be triggered by HikaShop after discounts/coupons are deleted, $elements is an array with a list of discount/coupon ids.

I'm sorry but the trigger you're using is not when a customer remove a coupon code in his checkout ; it's when a discount is delete from the database.

You should take a look at the trigger "onBeforeCouponLoad(&amp;$coupon,&amp;$do)" instead.

Regards,

---

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

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

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