Woocommerce get products
You can retrieve a list of products in WooCommerce using the 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 get_products()
to retrieve a list of all published products:
<?php
$args = [
'status' => 'publish',
];
$products = wc_get_products($args);
foreach ($products as $product) {
// Do something with the product object.
}
Watch a video course
Learn object oriented PHP
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 get_products()
function documentation in the WooCommerce codebase.