I found a solution using chatgpt while waiting for it to be natively possible:
You:
In Bricks Builder 2.2 I want to add a condition.
I want to display a text if there is a product in my cart that has a “made to order / on order” status (“sur commande”).
Currently Bricks only supports “in stock”, “out of stock” and “on backorder”, but “on backorder” and “made to order / sur commande” are not the same.
Me:
You can do this cleanly with a “Dynamic Data” condition in Bricks, based on a PHP function that checks the cart contents.
Bricks can’t (yet) handle your “sur commande” status if it’s a custom stock status, so we “provide” it a 1/0 value that can be used in a condition.
1) Add this mini-plugin (recommended as an MU-plugin)
Create this file:
wp-content/mu-plugins/es-bricks-cart-stock-status.php
(if the mu-plugins folder doesn’t exist, create it)
<?php
/**
* Plugin Name: ES - Bricks Condition (Cart stock status)
* Description: {echo:...} functions to show/hide Bricks elements depending on products' stock status in the cart (e.g. “sur commande”).
* Version: 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Bricks 1.9.7+ : you must whitelist functions called via {echo:...}
*/
add_filter( 'bricks/code/echo_function_names', function( $names ) {
$names[] = 'es_cart_has_stock_status';
$names[] = 'es_cart_stock_statuses_in_cart'; // debug
return $names;
} );
/**
* Returns 1 if at least one product in the cart has the requested stock_status, otherwise 0.
* Examples: instock, outofstock, onbackorder, or a custom slug (e.g. sur-commande)
*/
function es_cart_has_stock_status( $status_slug ) {
$status_slug = is_string( $status_slug ) ? trim( $status_slug ) : '';
if ( $status_slug === '' ) return 0;
if ( ! function_exists( 'WC' ) ) return 0;
$wc = WC();
if ( empty( $wc ) || empty( $wc->cart ) ) return 0;
foreach ( $wc->cart->get_cart() as $item ) {
$product = $item['data'] ?? null;
if ( ! $product || ! is_a( $product, 'WC_Product' ) ) continue;
$item_status = method_exists( $product, 'get_stock_status' ) ? $product->get_stock_status() : '';
if ( $item_status === $status_slug ) return 1;
}
return 0;
}
/**
* DEBUG: returns "Product name => status_slug | ..."
* Useful to find the exact slug of your “sur commande”.
*/
function es_cart_stock_statuses_in_cart() {
if ( ! function_exists( 'WC' ) || ! WC()->cart ) return '';
$out = [];
foreach ( WC()->cart->get_cart() as $item ) {
$product = $item['data'] ?? null;
if ( ! $product || ! is_a( $product, 'WC_Product' ) ) continue;
$out[] = $product->get_name() . ' => ' . $product->get_stock_status();
}
return implode( ' | ', $out );
}
2) Find the exact slug of your “sur commande” status
On a page where the cart is visible, temporarily output:
{echo:es_cart_stock_statuses_in_cart()}
You’ll see values like:
instock
outofstock
onbackorder (often translated as “on backorder” / “en commande”)
Your “sur commande” will also have a slug (e.g. sur-commande, sur_commande, etc.).
If you don’t have a custom slug and it’s just WooCommerce backorders, it will be onbackorder.
3) Bricks condition (on your text element)
In the Text element > Conditions:
- Add a Dynamic Data condition
- Dynamic data value:
- if your custom slug is
sur-commande:
{echo:es_cart_has_stock_status('sur-commande')}
- if it’s standard WooCommerce backorder:
{echo:es_cart_has_stock_status('onbackorder')}
- Operator: equals
- Value: 1
Important: in {echo:...}, function arguments should use single quotes.
Useful notes
- If you show this in a header with aggressive caching, the text may not update until refresh. Make sure cart/checkout pages aren’t cached.
- If you want it to update instantly in an AJAX mini-cart, we can hook into WooCommerce fragments (but first test this version — it works perfectly on cart/checkout pages).