Skip Navigation

[Resolved] Displaying Content Conditionally if post type is WooCommerce Product

This support ticket is created 6 years, 1 month ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by Nashaat 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1126152

I am trying to display content conditionally if the post type is products of WooCommerce.

This solution work for other post type just fine. but when i insert "product" as a slug it seems not to work

WORKS FINE:

[wpv-conditional if="( '[wpv-post-type]' eq 'post' )"]
    THIS is PRODUCT POST TYPE
    [/wpv-conditional]

DOESN'T WORK:

[wpv-conditional if="( '[wpv-post-type]' eq 'product' )"]
    THIS is PRODUCT POST TYPE
    [/wpv-conditional]
#1126229

Nigel
Supporter

Languages: English (English ) Spanish (Español )

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

Where are you using this?

I created a content template for single product posts and added the following

<p>Post type: [wpv-post-type]</p>

[wpv-conditional if="( '[wpv-post-type]' eq 'product' )"]
This is a product
[/wpv-conditional]

It outputs

Post type: product
This is a product

I suspect the context where you are using it is wrong.

#1126267
Frontend-Render.png

Thanks Nigel for your Reply.

I have tested your code and i found a problem with the slug name of the post type which causing this Issue.

following code wont work:

<p>Post type: [wpv-post-type] </p>
[wpv-conditional if="( '[wpv-post-type]' eq 'product' )"]
This is a product
[/wpv-conditional]

following code works:

<p>Post type: [wpv-post-type] </p>
[wpv-conditional if="( '[wpv-post-type]' eq '/product' )"]
This is a product
[/wpv-conditional]

I dont know why the slug name is adding an extra "/" , please see screenshot.

maybe this also connected to this unsolved ticket? https://toolset.com/forums/topic/text-issue-when-using-special-character-like/

BTW i am using the code in Toolset Cred form and tried to use it in Layout Template but the issue is in both cases there.

#1126285

Nigel
Supporter

Languages: English (English ) Spanish (Español )

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

It's not the same issue (backslash to escape characters on the other thread, a forward slash in this thread).

Can you confirm if this happens when you disable all plugins except Toolset and WooCommerce, and switch theme to twentyseventeen?

What is the language of your site?

#1126320

I will follow your suggestion and let you know if this helps!
Its Hebrew

Thanks

#1126908

My issue is resolved now. Thank you!

I have followed all your suggestions but seems not to work.
I have looked at the permalinks and changed the "Product permalinks" from custom to default and saved.
this has automatically deleted an extra backlash from the permalink from "/product/" to "product/"