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

Related Tutorials..

Pro
On Sale Ribbon for WooCommerce Products Query Loop in Bricks

On Sale Ribbon for WooCommerce Products Query Loop in Bricks

Showing a SALE ribbon for products that are output using Bricks‘ Query Loop.
Categories:
Side-by-side WooCommerce Quantity and Add to Cart in Bricks

Side-by-side WooCommerce Quantity and Add to Cart in Bricks

Looking to position the quantity input field and Add to cart button next to each other instead of one below the other in Bricks? Add…
Categories:
[WooCommerce] Product Category Image Background in Bricks

[WooCommerce] Product Category Image Background in Bricks

How to set up the product category thumbnail image as the background of a Section.
Categories:
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:
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:
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: