Skip Navigation

[Gelöst] Conditional output based on cart input

This support ticket is created vor 2 Jahre. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 2 Antworten, has 2 Stimmen.

Last updated by Pat vor 2 Jahre.

Author
Artikel
#2316241

Pat

Hello,

I need to use a conditional output (in order to display or not the BUY button on specific pages). This conditional output is based on one of these 2 conditions (OR) :
1. The user is connected and has a specific role => no issue for that
2. The user is connected and a product of a specific category (inscription) has been placed on the cart (but the cart validation has not been done).
Can you help on how to setup the second part of the condition?
Regards
Pat

#2316255

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+00:00)

Hi Pat

You'll need to write a custom function to check if a product is in the cart, and you can then use the results of that function in your condition. (Don't forget to register the custom function at Toolset > Settings > Front-end content.)

I don't find the WooCommerce API docs very easy to navigate, but I found this article about retrieving the cart which shows how to get the cart contents and loop through them: hidden link

For each product you can check if it has the product category assigned you are concerned with.

#2316981

Pat

Hi Nigel,

Got it.
Thanks
Pat

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.