Skip Navigation

[Resolved] Using Custom Shortcode Attributes with Conditional Display

This support ticket is created 7 years, 10 months 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Jeffrey McQuillan 7 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#462583

I want to use the Woocommerce Membership plugin shortcode [wcm_restrict plans=“XYZ”] to show something to those who have a subscription membership and something to different to:
1. Anyone who is a member of another plan (and *not* a subscriber - I have lots of non-subscription membership plans)
2. Anyone not logged in.

I have wcm_restrict registered as a custom shortcode, and thought I could use the conditional shortcode. The shortcode has "plans=" attribute to allow you to show one thing to members of Plan X and another thing to members of Plan Y. However, I have dozens of plans - I just want to distinguish between subscriber members and non-subscriber members.

It does not seem to be possible to do, say, this:

[wpv-conditional if="( '[wcm_restrict plans]' eq 'select-english-membership-plan' )"] SHOW SOMETHING HERE [/wpv-conditional]

Or

[wpv-conditional if="( '[wcm_restrict field="plans"]' eq 'select-english-membership-plan' )"] SHOW SOMETHING HERE [/wpv-conditional]

Can I specify attributes within the custom shortcode (e.g. plans=XYZ) in some way so as to show content to only those who are in fact members of the plan linked to my subscription service?

If I could show things to only those whose role=subscriber (using wpv-user?) that would work for me also, I think. But wpv-user seems limited to displaying fields rather than being part of a conditional statement, from my testing so far.

Jeff

#462696

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes - you can use shortcode attribute with your custom shortcode. However you can check current user role as given under:

Could you please try to use following code:

[wpv-conditional if="('[wpv-current-user info='role']' eq  'subscriber')"]
dispaly this content if user role = subscriber
[/wpv-conditional]

Please have look at following documentation that may help you:
=> https://toolset.com/documentation/views-shortcodes/#wpv-current-user
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#463595

Great! The subscriber role code worked perfectly. Thank you so much!
Jeff

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