19th Jan '23
/
1 comment

Check if the User Purchased Any of the Specified Products

This Pro tutorial provides the steps for setting up a dynamic data condition on any element in Bricks so it can be output only if the logged-in user has purchased any of the WooCommerce products specified by their ID(s).

After adding the code for a custom function named bl_has_user_purchased_any_of_these_products, you will be able to add a condition like this:

{echo:bl_has_user_purchased_any_of_these_products(2076, 2164)}

This Section will then be rendered only if the currently logged-in user bought at least one of the two specified products (having the ID of 2076 or 2164). For everyone else incl. the guest visitors, the Section will not be output.

To conditionally check and output if the user has purchased a single product with the ID of 2076:

{echo:bl_has_user_purchased_any_of_these_products(2076)}

Step 1

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

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Condition based on WooCommerce Product Attributes in Bricks

Condition based on WooCommerce Product Attributes in Bricks

How to display elements only when a specific WooCommerce product attribute is selected.
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…
Pro
Stock Quantity Block for WP Grid Builder

Stock Quantity Block for WP Grid Builder

In the unofficial WP Grid Builder Facebook group a user asked: Is it possible to show stock quantity on the card? I can't find it…
Categories:
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:
Pro
User Role Conditional Output in Bricks

User Role Conditional Output in Bricks

This Pro tutorial provides the steps to output elements based on their CSS class to users of the specified role in WordPress when using Bricks…
Categories:
Pro
[WooCommerce] Sale price dates in Bricks

[WooCommerce] Sale price dates in Bricks

Outputting start and end sale price dates (if set) for WooCommerce products.
Categories: