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 526 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..

Pro
Custom Conditions in Bricks Builder

Custom Conditions in Bricks Builder

Updated on 22 Jun 2022 This Pro tutorial is a continuation of the previous Conditions in Bricks Builder tutorial. We are going to keep updating…
Categories:
Conditionally Outputting Based on Query Count in Bricks

Conditionally Outputting Based on Query Count in Bricks

Update on 22 Sep 2023: There's a much simpler built-in method now. See this post. In the Bricks Facebook group a user asks: Is there…
Categories:
Render an element having a specific HTML ID based on value of a custom field

Render an element having a specific HTML ID based on value of a custom field

This tutorial provides the steps to use Bricks' bricks/element/render filter to conditionally output an element that has the specified HTML ID based on the value…
Categories:
Pro
Conditional Rendering Based On Meta Box Group’s Sub Field

Conditional Rendering Based On Meta Box Group’s Sub Field

This Pro tutorial shows how we can output an element on a single post pages only if a specified sub-field (custom field created using Meta…
Weekday Condition in Bricks

Weekday Condition in Bricks

As of Bricks 1.7, the built-in "Weekday" condition does not work correctly. This is most likely due to it not taking the site's timezone (set…
Categories:
Pro
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories:
Pro
Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

This Pro tutorial provides the steps to modify a ACF Repeater query loop to only output the rows for which a True / False type…
Categories: