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 612 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Condition for checking Bricks content

Condition for checking Bricks content

Only outputting Bricks content when a Page is built with Bricks, otherwise display WP content.
Categories:
Pro
Host Post’s Term in Bricks Query Loop

Host Post’s Term in Bricks Query Loop

Updated on 4 Mar 2025 In the BricksLabs Facebook group a user asked: Hi everyone, I’m facing a tricky situation that might have a simple…
Categories:
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
Primary Term Name and Link in Bricks when using Rank Math

Primary Term Name and Link in Bricks when using Rank Math

One of the features of the Rank Math SEO plugin is the ability to mark a term like category or product category as primary. See…
Pro
Media File Attachment Data in Bricks

Media File Attachment Data in Bricks

With a 'Media' query loop, this tutorial shows how we can retrieve various attachment-specific properties inside of the loop.
Categories:
Pro
ACF Repeater sub field value dynamic data condition in Bricks

ACF Repeater sub field value dynamic data condition in Bricks

This Pro tutorial provides the steps to output an element on single posts (can be of any post type) only if a specified ACF (Pro)…
Pro
[WooCommerce] Sticky on Scroll Add to Cart section in Bricks

[WooCommerce] Sticky on Scroll Add to Cart section in Bricks

Setting up a sticky section that fades in when scrolling down and fades away when scrolled to the top.
Categories: