:::: MENU ::::

WooCommerce get all products

Today we talk about WooCommerce or WordPress get all products programmatically. In this tutorial, We focus on how to get all product data. In this example, we focus on getting all product information, information like product status, product type, product id, product title, and product price. You can use the following method to get all product wc_get_products. You can filter status to get products that are published 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 ) );

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');
}
Author: Qaisar Satti
Last Modified: June 9, 2021


Comments are closed.