Modules / Shop (WooCommerce)

Shop: order products by SKU, stock or sales

Products: order by SKU, stock, sales and custom meta

Sort a Products element, or the front-end Sort by dropdown, by SKU, stock quantity, total sales, weight or any product meta key you add. Products that have no value for the field stay in the list. You can also put out-of-stock products, or products without a value, at the end of any sort.

#4 of 39 modules by votes

  • On by default
  • Needs Bricks 2.4 or newer, and WooCommerce 11.1 or newer
  • Tested with Bricks 2.4.3
Recording: someone opens a products element’s Order by list, where Kiln’s SKU and stock quantity sit after Bricks’ own options, and picks SKU; the product grid reorders by SKU.Recorded in Bricks 2.4.3

How to use it

Order a Products element

  1. Select the Products element and open its Query group.
  2. In Order by, choose SKU, Stock quantity, Total sales or Weight. Kiln adds these after Bricks' own options.
  3. Set the order direction on the element as usual. Both ascending and descending work.

Offer the choices to visitors

The same four choices are added to the options of the front-end Sort by dropdown (the Products order-by element).

Out-of-stock products last

  1. On the Products element, tick Out of stock last (Kiln) in the Query group. On a Container, Block or Div that loops over products, the checkbox is Products: out of stock last (Kiln), under the Query editor.
  2. Out-of-stock products now follow the in-stock ones. Each part keeps the order you chose, whether that is price, rating, name or a Kiln field. Products on backorder count as in stock.

Products without a value last

Tick Empty values last (Kiln) on the Products element. When it sorts by a Kiln field (SKU, stock, sales, weight or one of yours), products without a value go to the end in both directions. Other sorts ignore it. With both checkboxes on, stock comes first: out-of-stock products are last, and inside each part the empty ones come last.

A custom meta key

  1. Open Bricks > Kiln and find this module's settings.
  2. In More fields to sort by, add one line per field: the meta key, a label, and text, number or decimal. For example: _my_rating | Rating | decimal.
  3. Save. The field now shows in Order by and in the Sort by dropdown under its label.

The label and the type are optional. Without a label, Kiln shows the key; without a type, it sorts as text. A line with the same key as a built-in choice replaces that choice's label and type.

In code

Developers can add or change keys with the kiln/woo/orderby_meta_keys filter. It runs after the settings, so code wins:

add_filter( 'kiln/woo/orderby_meta_keys', function ( $keys ) {
	$keys['_my_rating'] = [
		'label' => 'My rating',
		'type'  => 'DECIMAL(10,3)',
	];
	return $keys;
} );

In code, the type is CHAR (sorts as text), SIGNED, UNSIGNED, NUMERIC or DECIMAL(p,s). Kiln treats any other type as CHAR. Kiln skips a key with anything but lowercase letters, digits and underscores.

Where it appears in Bricks

  • Products element, Query group: Order by, then Out of stock last (Kiln) and Empty values last (Kiln) under Order.
  • Container, Block, Div with a query loop: Products: out of stock last (Kiln), under the Query editor.
  • The front-end Sort by dropdown of the Products order-by element.

Products without a value

A product with no stored value for the field stays in the list. It comes first when you sort ascending and last when you sort descending, unless Empty values last is on. Products with the same value, such as several with stock 0, are ordered by product ID, lowest first, so pagination stays stable.

Limits

  • The choices work for Bricks product queries only. Kiln leaves WooCommerce's own shop archive query alone. A query loop or Products element set as the archive's main query keeps both checkboxes.
  • If WooCommerce hides out-of-stock products (WooCommerce > Settings > Products > Inventory), there is nothing to move, and Out of stock last has no effect.
  • Out of stock last reads the stock status WooCommerce keeps in its product lookup table. A product missing from that table counts as in stock. If stock looks wrong, run Product lookup tables under WooCommerce > Status > Tools.
  • A search or filter plugin that rewrites the whole sort of a query after Kiln drops both checkboxes for that query.
  • The built-in choices read these meta keys: _sku, _stock, total_sales and _weight.
  • Price is not in the list. Variable products store several price rows, and Bricks already has a Price option.
  • Custom keys may hold lowercase letters, digits and underscores only. WooCommerce lowercases the value, and Bricks splits it at a dash.
  • number sorts whole numbers (4.5 counts as 4); use decimal for prices, ratings and weights.
  • Bricks query loops already let you order by a meta key, and a Filter - Select or Radio set to Sort offers a meta sort to visitors. This module covers the Products element and the Sort by dropdown.
  • Bricks' Popularity order already sorts by total sales, highest first. Kiln's Total sales adds lowest first, and the out-of-stock and empty rules.

Settings

More fields to sort by: one line per field, as meta_key | Label | text, number or decimal. When you save, Kiln drops lines it can't use (a capital letter, a dash, an unknown type, more than three parts). Up to 50 fields.

Requirements

Bricks 2.4 or newer, and WooCommerce 11.1 or newer.