Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection

HandlerRegistry::get_recent_product_ids_queryprivateWC 1.0

Get a query that returns the most recent published products. Used as a fallback for preview mode when the specific collection query might return no results (e.g., no best sellers yet in a new store).

Method of the class: HandlerRegistry{}

No Hooks.

Returns

Array. Query args to show recent products.

Usage

// private - for code of main (parent) class only
$result = $this->get_recent_product_ids_query();

HandlerRegistry::get_recent_product_ids_query() code WC 10.8.1

private function get_recent_product_ids_query() {
	$recent_product_ids = wc_get_products(
		array(
			'status'  => 'publish',
			'orderby' => 'date',
			'order'   => 'DESC',
			'limit'   => 10,
			'return'  => 'ids',
		)
	);

	return array(
		'post__in' => ! empty( $recent_product_ids ) ? $recent_product_ids : array( -1 ),
	);
}