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

#   Check if cart is empty in plugin

##

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

Less More

- Posts: 217
- Thank you received: 4
-
-

11 years 8 months ago [\#192854](#192854) by [FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")  *[Check if cart is empty in plugin](/forum/31-development/875364-check-if-cart-is-empty-in-plugin#192854 "-- HikaShop version -- : 2.3.5  Hello,  please I need to check if a cart is empty in my plugin (onBeforeCartUpdate) I tried everything but I didn't succeed.  Many thanks! Filip")* was created by *[FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")*

-- HikaShop version -- : 2.3.5

Hello,

please I need to check if a cart is empty in my plugin (onBeforeCartUpdate)
I tried everything but I didn't succeed.

Many thanks!
Filip

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg3NTM2NC1jaGVjay1pZi1jYXJ0LWlzLWVtcHR5LWluLXBsdWdpbj90bXBsPW1hcmtkb3du) 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: 26400
- Thank you received: 4079
-
- [](http://obsi.dev)
-

11 years 8 months ago [\#192858](#192858) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Check if cart is empty in plugin](/forum/31-development/875364-check-if-cart-is-empty-in-plugin#192858 "-- HikaShop version -- : 2.3.5  Hello,  please I need to check if a cart is empty in my plugin (onBeforeCartUpdate) I tried everything but I didn't succeed.  Many thanks! Filip")*

Hi,

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

As you can see in the documentation, the $cart contains the future new cart.
So if you want the old cart, the best is to load it using the $cartClass ; like calling "$cartClass-&gt;loadCart()"

Regards,

---

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

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

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

Less More

- Posts: 217
- Thank you received: 4
-
-

11 years 8 months ago [\#192946](#192946) by [FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")  Replied by *[FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")* on topic *[Check if cart is empty in plugin](/forum/31-development/875364-check-if-cart-is-empty-in-plugin#192946 "-- HikaShop version -- : 2.3.5  Hello,  please I need to check if a cart is empty in my plugin (onBeforeCartUpdate) I tried everything but I didn't succeed.  Many thanks! Filip")*

Thank you!
So how can I check number of items in cart, or whether is empty?
Thanks

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

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

11 years 8 months ago [\#193082](#193082) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Check if cart is empty in plugin](/forum/31-development/875364-check-if-cart-is-empty-in-plugin#193082 "-- HikaShop version -- : 2.3.5  Hello,  please I need to check if a cart is empty in my plugin (onBeforeCartUpdate) I tried everything but I didn't succeed.  Many thanks! Filip")*

Hi,

To check the content of the old cart, you can do: Code:

$cartClass = hikashop_get('class.cart'); $oldCart = $cartClass-&gt;get(); if(!empty($oldCart)){ //... }

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

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

Less More

- Posts: 217
- Thank you received: 4
-
-

11 years 8 months ago [\#193170](#193170) by [FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")  Replied by *[FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")* on topic *[Check if cart is empty in plugin](/forum/31-development/875364-check-if-cart-is-empty-in-plugin#193170 "-- HikaShop version -- : 2.3.5  Hello,  please I need to check if a cart is empty in my plugin (onBeforeCartUpdate) I tried everything but I didn't succeed.  Many thanks! Filip")*

Hello Xavier,

that is exacly what I needed.
Thanks you!

Filip

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

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