How to Show Out of Stock Products in WooCommerce

Today we talk about WooCommerce or WordPress showing all Out of Stock products programmatically. In this tutorial, We focus on how to get all Out of Stock product data. In this example, we focus on getting all Out of Stock product information, like product status, product type, product id, product title, and product price. You can use the following method to get all products wc_get_products. You can filter status to get published products and use limit filter -1 to get all the products.

Let’s start with our example.

$products = wc_get_products( array( 'status' => 'publish','limit' => -1 ,'stock_status' => 'outofstock', ) );


foreach ( $products as $product ){ 
    echo  $product->get_status();  // Product status
    echo  $product->get_type();  // Product type
    echo  $product->get_id();    // Product ID
    echo  $product->get_title(); // Product title
    echo  $product->get_slug(); // Product slug
    echo  $product->get_price(); // Product price
    echo  $product->get_catalog_visibility(); // Product visibility
    echo  $product->get_stock_status(); // Product stock status
    // product date information
    echo $product->get_date_created()->date('Y-m-d H:i:s');
    echo $product->get_date_modified()->date('Y-m-d H:i:s');
}

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!