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

#   remove products from cart when checking out programmatically

##

- **[twscott](/forum/user/43011-twscott "View twscott's Profile")**
- [![twscott's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/gallery/beer.png)](/forum/user/43011-twscott "View twscott's Profile") Topic Author
- [ Offline](/forum/user/43011-twscott)

Less More

- Posts: 252
- Thank you received: 1
-
-
-
-

8 years 5 months ago [\#294064](#294064) by [twscott](/forum/user/43011-twscott "View twscott's Profile")  *[remove products from cart when checking out programmatically](/forum/27-checkout/894998-remove-products-from-cart-when-checking-out-programmatically#294064 "-- HikaShop version -- : 3.4.0  hi, In our shop, when user buy more than $500, he could choose a free gift into cart. While in checking out, user remove the products from cart we need to check if the gift need to be removed, Could you tell me which program and how to achieve that?  Thanks")* was created by *[twscott](/forum/user/43011-twscott "View twscott's Profile")*

-- HikaShop version -- : 3.4.0

hi,
In our shop, when user buy more than $500, he could choose a free gift into cart.
While in checking out, user remove the products from cart we need to check if the gift need to be removed,
Could you tell me which program and how to achieve that?

Thanks

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NDk5OC1yZW1vdmUtcHJvZHVjdHMtZnJvbS1jYXJ0LXdoZW4tY2hlY2tpbmctb3V0LXByb2dyYW1tYXRpY2FsbHk/dG1wbD1tYXJrZG93bg==) 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: 86587
- Thank you received: 14326
-
-

8 years 5 months ago [\#294065](#294065) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[remove products from cart when checking out programmatically](/forum/27-checkout/894998-remove-products-from-cart-when-checking-out-programmatically#294065 "-- HikaShop version -- : 3.4.0  hi, In our shop, when user buy more than $500, he could choose a free gift into cart. While in checking out, user remove the products from cart we need to check if the gift need to be removed, Could you tell me which program and how to achieve that?  Thanks")*

Hi,

You have these triggers which are called each time a product is added or removed from the cart:
onAfterProductCheckQuantities(&amp;$products, &amp;$cart, $options)
onBeforeCartSave( &amp;$cart, &amp;$do)
onAfterCartSave( &amp;$cart)
so you can implement a trigger in a plugin of the group "hikashop" and do the code you want there.
Beware of the fact that if you update the cart with the functions of class.cart while you are in these triggers, you might risk creating a loop which will crash the processing of the page.

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

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

- **[twscott](/forum/user/43011-twscott "View twscott's Profile")**
- [![twscott's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/gallery/beer.png)](/forum/user/43011-twscott "View twscott's Profile") Topic Author
- [ Offline](/forum/user/43011-twscott)

Less More

- Posts: 252
- Thank you received: 1
-
-
-
-

8 years 5 months ago [\#294203](#294203) by [twscott](/forum/user/43011-twscott "View twscott's Profile")  Replied by *[twscott](/forum/user/43011-twscott "View twscott's Profile")* on topic *[remove products from cart when checking out programmatically](/forum/27-checkout/894998-remove-products-from-cart-when-checking-out-programmatically#294203 "-- HikaShop version -- : 3.4.0  hi, In our shop, when user buy more than $500, he could choose a free gift into cart. While in checking out, user remove the products from cart we need to check if the gift need to be removed, Could you tell me which program and how to achieve that?  Thanks")*

Thanks, Nicolas, It works.
But there is a new issue that, the product is removed from the cart in database, but in the front end, the product is still there.
How can I refresh cart in the front end?

Thanks again

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NDk5OC1yZW1vdmUtcHJvZHVjdHMtZnJvbS1jYXJ0LXdoZW4tY2hlY2tpbmctb3V0LXByb2dyYW1tYXRpY2FsbHk/dG1wbD1tYXJrZG93bg==) 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: 86587
- Thank you received: 14326
-
-

8 years 5 months ago [\#294210](#294210) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[remove products from cart when checking out programmatically](/forum/27-checkout/894998-remove-products-from-cart-when-checking-out-programmatically#294210 "-- HikaShop version -- : 3.4.0  hi, In our shop, when user buy more than $500, he could choose a free gift into cart. While in checking out, user remove the products from cart we need to check if the gift need to be removed, Could you tell me which program and how to achieve that?  Thanks")*

Hi,

You'll need to clear the cache of the cart in class.cart and in the checkoutHelper after you change the cart data in the database. I think something like that should help : Code:

hikashop_get('helper.checkout'); $checkoutHelper = hikashopCheckoutHelper::get(); $cartClass = hikashop_get('class.cart'); $cachedCart = $checkoutHelper-&gt;getCart(); $cartClass-&gt;get('reset_cache',$cachedCart-&gt;cart_id); $checkoutHelper-&gt;getCart(true);

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

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