Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Display "Low Stock" Message on WooCommerce Product Page Instead of "Only # Left in Stock"
/* Change the 'Only # left in stock' message on the WooCommerce product page to
* simply show 'Low Stock'.
* Add to your theme's functions.php file
function custom_stock_totals($availability_html, $availability_text, $product) {
if (substr($availability_text,0, 4)=="Only") {
$availability_text = "Low Stock";
$availability_html = '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability_text ) . '</p>';
return $availability_html;
add_filter('woocommerce_stock_html', 'custom_stock_totals', 20, 3);
Copy link

logichub commented Jun 3, 2015

I am getting PHP Parse error after adding this snippet. Here is the error:

PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /www/wp-content/themes/notio-wp/functions.php on line 271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment