Skip to content

Instantly share code, notes, and snippets.

@bradleysa
Created April 22, 2022 07:57
Show Gist options
  • Save bradleysa/e2574b193032d3be40cd5b0b3c78b10f to your computer and use it in GitHub Desktop.
Save bradleysa/e2574b193032d3be40cd5b0b3c78b10f to your computer and use it in GitHub Desktop.
WC: Custom Low Stock message
/* 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 = "Supplies are running low! Get your jam!";
}
$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);
/** https://support.woothemes.com/hc/en-us/articles/203178095-How-to-display-Low-Stock-instead-of-Only-x-left-in-stock-on-product-page **/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment