Home » WooCommerce: Stock Quantity Suffix e.g. “sq. in.”, “Kg”, “boxes”, etc.

WooCommerce: Stock Quantity Suffix e.g. “sq. in.”, “Kg”, “boxes”, etc.

by adminkys

Each WooCommerce business is different, which means customization is required to adapt the store to unique specifications.

A clear example is the stock quantity. Not all stores can display the standard notice “11 in stock”. The display could change to “11 Kg in stock” if stock is based on weight. Or maybe “11 boxes in stock” or “11 pairs in stock” in case the package description is useful UX-wise. Also, “11 m3 in stock” if the business sells volumes.

Either way, this is a nice trick to display a “stock quantity suffix” in your WooCommerce Single Product Page. Enjoy!

In this example, I’ve added “m2” suffix to the stock quantity on the WooCommerce Single Product Page. Easy peasy with the PHP snippet below!

PHP Snippet: Stock Quantity Suffix @ WooCommerce Single Product Page

/**
 * @snippet       Stock Quantity Suffix @ WooCommerce Single Product
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 5
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_format_stock_quantity', 'tutoraspire_stock_quantity_suffix', 9999, 2 );

function tutoraspire_stock_quantity_suffix( $stock_quantity, $product ) {
    $stock_quantity .= ' m2'; // CONCATENATE " m2"
    return $stock_quantity;
}

You may also like