Created
February 9, 2016 08:14
-
-
Save themepaint/24c0b846d09e67e32bf5 to your computer and use it in GitHub Desktop.
Display “ Out of Stock ” on catalog view Woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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