How to Show In Stock Products in WooCommerce

Today we talk about WooCommerce or WordPress showing all In Stock products programmatically. In this tutorial, We focus on how to get all in Stock product data. In this example, we focus on getting all in 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' => 'instock', ) );


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');
}

Search

Recent Blogs

Categories

Archives

Archives

Tags