17th Sep '24
/
0 comments

Displaying SureCart Featured Products & Products Collections with a Query Loop

SureCart v3 (currently in beta) integrates with Bricks, allowing us to get the products ‘the Bricks way’ using query loops. We have a few new elements, and lots of dynamic tags for displaying different product data.

Surecart products grid

One nice thing is that most product data is available through dynamic tags, rather than having to display things with individual elements. This means we can use it for both displaying that data using native elements & also use the same for element conditions.

It’s a more flexible approach, at the cost of being a little bit more difficult for beginners. For example, there are no ‘Product Title’, ‘Product Image’, ‘Product Price’, ‘Product List’ elements that some may be looking for when first getting started. Instead, we use native Bricks elements for the most part, and then populate with the needed dynamic tags.

Workflow for Displaying Product Grids

In this tutorial, we’ll go through..

  1. How to use a query loop to display SureCart products generally.
  2. How to display only the ‘featured’ products.
  3. How to display a specific collection of products.

1. Using a Query Loop to Display Products.

Before we look at the featured products and collections we’ll go through how to display products generally using Bricks’ query loop and then narrow it down to specific products.

The SureCart products are a custom post type so, as expected, the first step is just to add a query loop to a block element with the type ‘Posts’ and the post type ‘SureCart Product’. We won’t see any products appear until we add something inside of the loop.

query loop settings, choosing surecart product from the list.

Adding the Product Card Element

Next a ‘Product Card’ element needs to be added inside the query loop. This is an important step because, without this card element, certain elements won’t function. An add-to-cart button wouldn’t work, and sales badges wouldn’t display, for example.

Update – Any interactive elements you may wish to add inside of a product grid, like buttons that trigger popups or popovers for showing more info, would need to be outside of the product card (inside of the query loop, but outside of that product card element). This is because any buttons found inside of the product card, SureCart will use them as ‘add to cart buttons’. So having a combination of some elements being inside of the card, and some outside of the card is going to work best in a lot of cases.

Thankfully, the product card element is nestable so doesn’t give us any restrictions. It auto-populates the structure with common things like the image, the title, price. All of this can be changed, but it’s a sensible starting point.

product grid, showing the structure on the right

As you can see from the image above, all of the elements are native Bricks elements inside of the card except for the Sales badge. The product image is an image element, the price is a text element. We’re then free to create any layout we like, as long as the SureCart-specific elements live inside that Product Card.

(By default the products would just be showing as a list, not a grid. But for the sake of a shorter tutorial, we’ll assume you’re familiar with Bricks’ grid or flex controls for creating grid layouts – I used Grid template columns repeat(3, minmax(0, 1fr) )

Now we can look at how to display more specific products using query loops.

Each SureCart product can be organized into ‘collections’ or tagged as ‘featured’. See the arrows on the image below.

screenshot of the edit product page, pointing out the featured and collections options

If we want to show only the products tagged as ‘featured’ we need to change the query loop settings to narrow it down to just those products. This is a better approach than just outputting all products and then adding conditions to remove some of them.

Inside the query loop settings, create a ‘Meta Query’ with the meta key as ‘featured’ and the meta value as 1. This will then only output the products that are marked as featured.

showing the meta query options in the query loop settings.

3. Displaying Products of a Specific Collection

For collections, they are a taxonomy. If you wish to display a list of products, (outside of the existing taxonomy archive page) instead of using the meta query we need to set a taxonomy query.

Inside the query loop settings, create a ‘Taxonomy Query’. Choose ‘Collections’ from the taxonomy dropdown, the field as ‘slug’, and then your taxonomy term slug for the collection under ‘Terms’.

showing the taxonomy query options

That’s it

Once the query loops are in place, then it’s pretty easy to customise from there and change the design, layout, display additional product data, and add anything conditonally based on the various dynamic tags (amount of stock, product price, product weight etc).

Get access to all 633 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Pro
Events grouped by months within years based on event date custom field value

Events grouped by months within years based on event date custom field value

How to output events grouped by years and months using three nested query loops in Bricks.
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

This tutorial provides the PHP & JS codes that can be pasted in order to create a dynamic map with markers populated from a custom…
Categories:
Pro
ACF User Field Bricks PHP Query

ACF User Field Bricks PHP Query

In the Bricks Facebook group a user asks: my end goal was to create a set of cards that would display the Users that are…
Categories:
Pro
Posts Grouped by Taxonomy Terms in Bricks using BricksExtras’ Dynamic Table and Pro Tabs

Posts Grouped by Taxonomy Terms in Bricks using BricksExtras’ Dynamic Table and Pro Tabs

How to output any post type, with the taxonomy terms as Tab titles and posts inside tables with sortable columns.
Pro
Top-level Pages and Children Bricks Query Loop

Top-level Pages and Children Bricks Query Loop

This Pro tutorial for Bricks users can be considered Part 2 or a variation of the earlier Bricks Query Loop for Top-level Parent Pages with…
Categories:
Pro
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories:
How to apply a custom query var to multiple query loops in Bricks

How to apply a custom query var to multiple query loops in Bricks

In this tutorial, we'll learn how to apply a PHP filter to modify the query var of multiple query loops in a single function Introduction…
Categories:
Pro
Dynamic Horizontal Posts Accordion in Bricks

Dynamic Horizontal Posts Accordion in Bricks

Update on 8 Sep 2024: You may want to follow the newer version that considers accessibility. Looking to make a Horizontal Image Accordion dynamic? This…