Created
February 10, 2015 15:56
-
-
Save ameeker/07236b753e9c3ea446ee to your computer and use it in GitHub Desktop.
Display stock availability in Woo
This file contains 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
// WooCommerce Display Stock Availability | |
add_action( 'woocommerce_single_product_summary', 'wcs_stock_text_shop_page', 25 ); | |
//create our function | |
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']) { | |
echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment