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

#   Check if a product is in cart on the checkout

##

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

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 6 months ago [\#199473](#199473) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  *[Check if a product is in cart on the checkout](/forum/27-checkout/876533-check-if-a-product-is-in-cart-on-the-checkout#199473 "-- HikaShop version -- : 2.4.0  Hi All!  I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.  Thanks, Bruce Atkinson")* was created by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")*

-- HikaShop version -- : 2.4.0

Hi All!

I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.

Thanks,
Bruce Atkinson

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NjUzMy1jaGVjay1pZi1hLXByb2R1Y3QtaXMtaW4tY2FydC1vbi10aGUtY2hlY2tvdXQ/dG1wbD1tYXJrZG93bg==) 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 6 months ago [\#199492](#199492) 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 a product is in cart on the checkout](/forum/27-checkout/876533-check-if-a-product-is-in-cart-on-the-checkout#199492 "-- HikaShop version -- : 2.4.0  Hi All!  I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.  Thanks, Bruce Atkinson")*

Hi,

I think that the best way for you will be to use the function "onAfterCartProductsLoad()" in a plugin to see the content of the cart.

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

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

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

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 6 months ago [\#199598](#199598) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Check if a product is in cart on the checkout](/forum/27-checkout/876533-check-if-a-product-is-in-cart-on-the-checkout#199598 "-- HikaShop version -- : 2.4.0  Hi All!  I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.  Thanks, Bruce Atkinson")*

AH, and that would return cart object? How would I check the products in the cart, would it be contained in something like
$cart-&gt;products[]
?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NjUzMy1jaGVjay1pZi1hLXByb2R1Y3QtaXMtaW4tY2FydC1vbi10aGUtY2hlY2tvdXQ/dG1wbD1tYXJrZG93bg==) 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 6 months ago [\#199601](#199601) 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 a product is in cart on the checkout](/forum/27-checkout/876533-check-if-a-product-is-in-cart-on-the-checkout#199601 "-- HikaShop version -- : 2.4.0  Hi All!  I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.  Thanks, Bruce Atkinson")*

Hi,

Yes exactly, the products will be in $cart-&gt;products.

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

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

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 4 months ago [\#206922](#206922) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Check if a product is in cart on the checkout](/forum/27-checkout/876533-check-if-a-product-is-in-cart-on-the-checkout#206922 "-- HikaShop version -- : 2.4.0  Hi All!  I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.  Thanks, Bruce Atkinson")*

For those interested, I wrote the below code and put it under the checkout-&gt;cart override. It checks to see if a custom product is in the cart - in this case product id 723 "R10 donation to Children at Risk Centres".

If not, it displays a link and notice that read the following:
"Click here to add R10.00 to your order for the Outreach Mission Fund for support of the Children at Risk Centres in Africa."
If the customer has clicked the donation link, the cart reads as follows:
"Thank you! Your donation to the Outreach Mission Fund is greatly appreciated."

Any comments to refactor/refine?
Code:

&lt;?php $cartClass = hikashop_get('class.cart'); $cart = $cartClass-&gt;loadFullCart(true); if ($cart) { $numberOfProducts = count($cart-&gt;products); for ($i=0; $i &lt; $numberOfProducts; $i++) { $productName[$i] = $cart-&gt;products[$i]-&gt;product_name; } if (in_array("R10 donation to Children at Risk Centres", $productName)) { ?&gt; &lt;div class="alert alert-success"&gt;&lt;strong&gt;Thank you!&lt;/strong&gt; Your donation to the Outreach Mission Fund is greatly appreciated.&lt;/div&gt;&lt;?php } else { ?&gt; &lt;div class="alert alert-warning"&gt;&lt;strong&gt;&lt;a href="/index.php?option=com_hikashop&amp;ctrl=product&amp;task=updatecart&amp;product_id=723&amp;quantity=1&amp;checkout=2"&gt;Click here to add R10.00&lt;/a&gt;&lt;/strong&gt; to your order for the Outreach Mission Fund for support of the Children at Risk Centres in Africa.&lt;/div&gt;&lt;?php } } ?&gt;

The following user(s) said Thank You: [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")

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

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

11 years 4 months ago [\#206931](#206931) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[Check if a product is in cart on the checkout](/forum/27-checkout/876533-check-if-a-product-is-in-cart-on-the-checkout#206931 "-- HikaShop version -- : 2.4.0  Hi All!  I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.  Thanks, Bruce Atkinson")*

Hello,
Thanks for your feedback !
The only comment that I'll add will be that using the **product ID** instead of the product name to find your custom product will be better. It will enable you to freely change its product name (the product ID won't be something that your customers will see).

The following user(s) said Thank You: [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")

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

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

Less More

- Posts: 42
- Thank you received: 2
-
-

11 years 4 months ago [\#207029](#207029) by [GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")  Replied by *[GSW00d](/forum/user/13067-gsw00d "View GSW00d's Profile")* on topic *[Check if a product is in cart on the checkout](/forum/27-checkout/876533-check-if-a-product-is-in-cart-on-the-checkout#207029 "-- HikaShop version -- : 2.4.0  Hi All!  I have added a custom add to cart link on my checkout that allows the client to donate R10 to a children at risk fund. At the moment I am using cookie values to check if the product was added, which then toggles the display of the donate link. This is sometimes producing weird results but works overall. I would prefer to be able to check if the product is in the cart, and then use that info to toggle the display link.  Thanks, Bruce Atkinson")*

For those interested, the updated code goes as follows:
Code:

&lt;?php $cartClass = hikashop_get('class.cart'); $cart = $cartClass-&gt;loadFullCart(true); if ($cart) { $numberOfProducts = count($cart-&gt;products); for ($i = 0; $i &lt; $numberOfProducts; $i++) { $productID[$i] = $cart-&gt;products[$i]-&gt;product_id; } if (in_array("723", $productID)) { ?&gt; &lt;div class="alert alert-success"&gt;&lt;strong&gt;Thank you!&lt;/strong&gt; Your donation to the Outreach Mission Fund is greatly appreciated.&lt;/div&gt;&lt;?php } else { ?&gt; &lt;div class="alert alert-warning"&gt;&lt;strong&gt;&lt;a href="/index.php?option=com_hikashop&amp;ctrl=product&amp;task=updatecart&amp;product_id=723&amp;quantity=1&amp;checkout=2"&gt;Click here to add R10.00&lt;/a&gt;&lt;/strong&gt; to your order for the Outreach Mission Fund for support of the Children at Risk Centres in Africa.&lt;/div&gt;&lt;?php } } ?&gt;

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

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