Skip Navigation

[Resuelto] Conditional output based on cart input

This support ticket is created hace 2 años, 8 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por Pat hace 2 años, 8 meses.

Autor
Mensajes
#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

Idiomas: Inglés (English ) Español (Español )

Zona horaria: 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: enlace oculto

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