Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themepaint/24c0b846d09e67e32bf5 to your computer and use it in GitHub Desktop.
Save themepaint/24c0b846d09e67e32bf5 to your computer and use it in GitHub Desktop.
Display “ Out of Stock ” on catalog view Woocommerce
function wcs_stock_text_shop_page() {
//returns an array with 2 items availability and class for CSS
global $product;
$availability = $product->get_availability();
//check if availability in the array = string 'Out of Stock'
//if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock'
if ( $availability['availability'] == 'Out of stock') {
echo apply_filters( 'woocommerce_stock_html', '<span class="' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
}
else{
echo '<span style="color:#6AC239"> In Stock </span>';
}
}
// For Display
<?php wcs_stock_text_shop_page(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment