W3docs

Woocommerce get products

You can retrieve a list of products in WooCommerce using the get_products() function.

You can retrieve a list of products in WooCommerce using the wc_get_products() function. This function accepts an array of arguments that you can use to customize the list of products that is returned.

Here is an example of how you can use wc_get_products() to retrieve a list of all published products:

How to get products in Woocommerce?

<?php

$args = [
  'status' => 'publish',
];

$products = wc_get_products($args);

if (empty($products)) {
  return;
}

foreach ($products as $product) {
  // Do something with the product object.
}

Requires WooCommerce 3.0 or later.

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

You can also use the $args array to filter the list of products by various criteria, such as product type, category, and more. For a full list of available arguments, you can refer to the wc_get_products() function documentation in the WooCommerce codebase.