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

Related Tutorials..

Pro
WooCommerce Product Carousel in Bricks

WooCommerce Product Carousel in Bricks

How to set up a carousel that shows WooCommerce products with the product title, price and Add to Cart button for each.
Categories:
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:
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
Top-Level Product Categories in Bricks

Top-Level Product Categories in Bricks

How to show top-level WooCommerce product categories in Bricks using a query loop.
Categories:
How to add a “Sold Out” badge for out of stock products in Bricks

How to add a “Sold Out” badge for out of stock products in Bricks

Looking to add a "Sold Out" badge for products in the Shop page for WooCommerce products that are out of stock when using Bricks' Products…
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: