PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]
Botoscope is currently in early access

Support Forum

You need to log-in to create request (topic) to the support

Adding a "Low Stock Label" badge

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi,

I'm using WOOT to display a product table (workshops with remaining seats). I can see an"Out of Stock Label" option for the stock column, but I'd like to also display a separate"Low Stock Label" badge (e.g."Almost Full") when the remaining stock falls below a certain threshold.

Is this feature available in the column settings, and if so, where can I configure the threshold and label text/color?

https://www.seniors.assomediagraph.fr/les-ateliers/

Thanks!

Hi Cecile

Thanks for the clear question.

There is no built-in"Low Stock Label" with a threshold in WOOT. The only stock related label at the moment is the"out of stock" one, so a separate"Almost Full" badge with its own threshold, text and color is not available as a ready option in the column settings.

The good news is that you can add it without any problem. WOOT lets you register your own column with any content you like, and then you style it with CSS however you want. For your case (workshops with a limited number of seats) this works out very nicely, because the threshold can come from WooCommerce itself, per product.

Here is the full setup.

1. Set the threshold in WooCommerce

WooCommerce already has a low stock threshold. You can set it globally under WooCommerce, Settings, Products, Inventory,"Low stock threshold", and you can also override it per product on the product's Inventory tab. So each workshop can have its own"almost full" point.

2. Add a custom column with the badge

Add this snippet to your child theme functions.php. It creates a new column that shows an"Almost Full" badge when the remaining stock is at or below the threshold (and still above zero):

add_filter( 'woot_columns_table', function ( $columns ) {
    // The filter is also called with NULL to collect keys - guard against it.
    if ( ! is_array( $columns ) ) {
        return $columns;
    }

    $columns['low_stock_badge'] = array(
        'title'  => 'Availability',
        'action' => function ( $post_id ) {
            $product = wc_get_product( $post_id );
            if ( ! $product ) {
                return '';
            }

            $qty = $product->get_stock_quantity();
            // Only for stock-managed products that are still in stock.
            if ( null === $qty || ! $product->is_in_stock() ) {
                return '';
            }

            // Per-product low stock amount, otherwise the global WooCommerce setting.
            $threshold = $product->get_low_stock_amount();
            if ( '' === $threshold || null === $threshold ) {
                $threshold = (int) get_option( 'woocommerce_notify_low_stock_amount', 2 );
            }

            if ( $qty > 0 AND $qty <= (int) $threshold ) {
                return '<span class="woot-low-stock-badge">Almost Full</span>';
            }

            return '';
        },
    );

    return $columns;
}, 20 );

After adding it, open your table settings and you will find a new column named"Availability" that you can enable and position wherever you want in the table. You can change the badge text ("Almost Full") directly in the snippet.

3. Style the badge with CSS

Add this to your theme's custom CSS and adjust the colors to match your site:

.woot-low-stock-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    background: #e8a33d;
    color: #fff;
    font-size: 12px;
    line-height: 1.6;
}

So in short: the threshold is controlled in WooCommerce (global or per product), the label text is in the snippet, and the color and shape are in the CSS. If you tell us the exact wording and color you want, we are happy to tailor the snippet for you.