WordPress at Your Fingertips
function is not described

wc_get_products() WC 3.0.0

Standard way of retrieving products based on certain parameters.

This function should be used for product retrieval so that we have a data agnostic way to get a list of products.

Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query

No Hooks.

Return

Array|stdClass. Number of pages and an array of product objects if paginate is true, or just an array of values.

Usage

wc_get_products( $args );
$args(array) (required)
Array of args (above).

Changelog

Since 3.0.0 Introduced.

Code of wc_get_products() WC 5.5.2

<?php
function wc_get_products( $args ) {
	// Handle some BW compatibility arg names where wp_query args differ in naming.
	$map_legacy = array(
		'numberposts'    => 'limit',
		'post_status'    => 'status',
		'post_parent'    => 'parent',
		'posts_per_page' => 'limit',
		'paged'          => 'page',
	);

	foreach ( $map_legacy as $from => $to ) {
		if ( isset( $args[ $from ] ) ) {
			$args[ $to ] = $args[ $from ];
		}
	}

	$query = new WC_Product_Query( $args );
	return $query->get_products();
}