15th Apr '24
/
2 comments

Product Attribute based Related Products Bricks Query Loop

This Pro tutorial provides the steps to output products related by value of attribute(s) for the current product on single WooCommerce product pages in Bricks.

Let's consider a product that has Gray color.

After implementing this tutorial, viewing this product on the front end will show:

(ignore the array data near the end)

where "T-Shirt with Logo" is the only other product in the site that also has color attribute with Gray value.

Another product that has multiple attribute values and hence the related products in this case are all the products that are blue or green or red:

Single Tutorial Purchase Option

Lifetime access to this single tutorial can be purchased for $39 here.

Step 1

Implement the Products in the Same Product Categories as the Current Product in Bricks tutorial.

Step 2

For the query loop-enabled Block, turn off PHP query.

Ensure that Post type is Products and Posts per page is a large number that is higher than the possible number of matching products any given time, now or in the future.

Re-enable the PHP query.

Replace the query loop's PHP query with:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 632 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
WooCommerce Products Live Search in Bricks

WooCommerce Products Live Search in Bricks

This Pro tutorial provides the steps to set up a live search for WooCommerce products in Bricks. Note: Bricks' live search works with any type…
Categories:
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
Similarly Priced WooCommerce Products Bricks Query Loop

Similarly Priced WooCommerce Products Bricks Query Loop

How to show products priced within a percentage of the current single product's price.
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:
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…
How To Remove the Featured Image from WooCommerce Product Gallery

How To Remove the Featured Image from WooCommerce Product Gallery

Product Gallery on single product pages in WordPress include the product's featured image by default. If you are looking to exclude it so only the…
Categories:
Pro
How to Redirect WordPress Search to WooCommerce Shop Filter by Product Title or SKU

How to Redirect WordPress Search to WooCommerce Shop Filter by Product Title or SKU

Learn how to redirect users to the Shop page with filtered results if the searched term matches a WC product title or SKU. And, if…
Categories: