17th Mar '23
/
5 comments

Bricks Condition for WishList Member

Looking to render a Bricks builder element only if the user has access to a specified WishList Member level?

Add the following in child theme‘s functions.php (w/o the opening PHP tag) or a code snippets plugin:

// Function to check if the current user belongs to the specified WishList Member level.
function bl_user_has_wlm_level( $level ) {
	return wlmapi_is_user_a_member( $level, get_current_user_id() );
}

and apply a dynamic condition like this:

{echo:bl_user_has_wlm_level(1679020379)}

where 1679020379 is the ID of the membership level.

Reference

https://wishlistmember.com/docs/knowledge-base/function-reference-wlmapi_is_user_a_member/

Get access to all 626 Bricks code tutorials with BricksLabs Pro

5 comments

  • Hi, this is great. Thanks Sridhar!

    Wondering how I would edit it so only manually approved users of a membership level can access? Looks like something to do with this:

    wishlistmember_approve_user_levels (action) Called when a member is approved on one or more levels Parameters: $id - Member ID $levels - Membership Levels

    For reference that is from: https://wishlistmember.com/docs/membership-level-hooks/?

    • A

      Hi Matt. Per my understanding that hook can not help identify whether a user got automatically added to a specific level or manually by the admin. Going by the description on that doc page of "Called when a member is added to one or more levels" I don't think it is referring to manual approval of users.

      Try contacting WLM support and ask if there is a function that returns a boolean (true or false) based on whether a given user has been manually approved or not. Keep us updated.

Leave your comment

 

Related Tutorials..

Conditionally Hide a Section on a Specific Taxonomy’s Term Archives in Bricks

Conditionally Hide a Section on a Specific Taxonomy’s Term Archives in Bricks

A user asked: I have a CTA in the footer of my site, which I have custom fields on various templates, etc to populate. I…
Categories:
Pro
Conditionally outputting an element in a Query Loop based on date-type custom field

Conditionally outputting an element in a Query Loop based on date-type custom field

This Pro tutorial shows how to output an element in a Bricks' query loop only if the value of a date-type of custom field for…
Categories:
Pro
Conditional Output in Bricks based on if Content has Headings

Conditional Output in Bricks based on if Content has Headings

How to prevent the output of the table of contents if the content has no headings.
Categories:
Tags:
Is WooCommerce Cart Empty Condition in Bricks

Is WooCommerce Cart Empty Condition in Bricks

Updated on 5 Nov 2024 Looking to conditionally render an element depending on whether the user's cart is empty or not when using WooCommerce? Add…
[Function] Current Term Has Children

[Function] Current Term Has Children

Updated on 20 Jul 2024 A user asks: I'm working on an archive template for WooCommerce products. I'm trying to hide a section if there…
Pro
Checking if the current Page/Post has Children i.e. is a Parent in Bricks

Checking if the current Page/Post has Children i.e. is a Parent in Bricks

Shows how we can check whether the current Page or Post (of any hierarchical post type) is a parent
Categories: