How to display 'Available' or 'Sold Out' on the main Shop page (Product List Page) in WooCommerce

Display Available or Sold Out in WordRress WooCommerce on main page_english

WooCommerce is a WordPress plugin which allows you converts your WordPress site to a full-fledged online store.  To display the label "Sold Out" (Out of Stock) or "Available" on the main Shop page (or product list page) in WooCommerce (as shown above), please add the following code to a template file under "/your_site/wp-content/plugins/woocommerce/templates/loop/":

global $product;
if ( $product->is_in_stock() )  {
echo '<span>Available</span>';
}

else {
echo '<span style="color: red";>Sold Out</span>';
}

I pasted the code above into the "price.php" file.

To display the number of available products, please use the following code:

$quantity=$product->get_stock_quantity( );

echo $quantity;

Please also see ...


Leave a Comment

3s