Skip to content

Instantly share code, notes, and snippets.

@ameeker
Created February 10, 2015 15:56
Show Gist options
  • Save ameeker/07236b753e9c3ea446ee to your computer and use it in GitHub Desktop.
Save ameeker/07236b753e9c3ea446ee to your computer and use it in GitHub Desktop.
Display stock availability in Woo
// 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