Show Stock Status in Shop Listings
Displays "In stock", "Only 3 left" or "Out of stock" under each product's price on the shop and category pages.
Opens WPIDE on
Code
add_action( 'woocommerce_after_shop_loop_item_title', function () {
global $product;
if ( ! $product instanceof WC_Product || $product->is_type( array( 'variable', 'grouped', 'external' ) ) ) {
return;
}
echo wp_kses_post( wc_get_stock_html( $product ) );
}, 15 );
Notes
Uses the same availability text as the product page.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.