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.

#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).

A custom meta key

Add the key in code with the kiln/woo/orderby_meta_keys filter. Give each key a label and a type:

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

The type is CHAR (sorts as text), SIGNED, UNSIGNED, NUMERIC or DECIMAL(p,s). Any other type is treated as CHAR. Kiln skips a key that has capital letters or a dash.

Where it appears in Bricks

  • Products element, Query group: Order by.
  • 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. 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. WooCommerce's own shop archive query is left alone.
  • 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 must be lowercase and contain no dash. WooCommerce lowercases the value, and Bricks splits it at the dash.
  • Bricks query loops already let you order by a meta key. This module covers the Products element and the Sort by dropdown.

Settings

None. Turn the module on in Bricks > Kiln (it is on by default).

Requirements

Bricks 2.4 or newer, and WooCommerce 11.1 or newer.