Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks

Products::count_user_products()private staticWC 1.0

Count the number of user created products. Generated products have the _headstart_post meta key.

Method of the class: Products{}

No Hooks.

Return

Int. The number of user created products.

Usage

$result = Products::count_user_products();

Products::count_user_products() code WC 9.0.1

private static function count_user_products() {
	$args = array(
		'post_type'   => 'product',
		'post_status' => 'publish',
		'fields'      => 'ids',
		'meta_query'  => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
			'relation' => 'OR',
			array(
				'key'     => '_headstart_post',
				'compare' => 'NOT EXISTS',
			),
			array(
				'key'     => '_edit_last',
				'compare' => 'EXISTS',
			),
		),
	);

	$products_query = new \WP_Query( $args );

	return $products_query->found_posts;
}