How to use it
Order a Products element
- Select the Products element and open its Query group.
- In Order by, choose SKU, Stock quantity, Total sales or Weight. Kiln adds these after Bricks' own options.
- 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
- 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.
- 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
- Open Bricks > Kiln and find this module's settings.
- In More fields to sort by, add one line per field: the meta key, a label, and
text,numberordecimal. For example:_my_rating | Rating | decimal. - 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_salesand_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.
numbersorts whole numbers (4.5 counts as 4); usedecimalfor 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.