Automattic\WooCommerce\Admin\API\Reports\Stock\Stats

DataStore::get_count()privateWC 1.0

Get count for the passed in stock status.

Method of the class: DataStore{}

No Hooks.

Return

Int. Count.

Usage

// private - for code of main (parent) class only
$result = $this->get_count( $status );
$status(string) (required)
Status slug.

DataStore::get_count() code WC 7.3.0

private function get_count( $status ) {
	global $wpdb;

	return (int) $wpdb->get_var(
		$wpdb->prepare(
			"
			SELECT count( DISTINCT posts.ID ) FROM {$wpdb->posts} posts
			LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON posts.ID = wc_product_meta_lookup.product_id
			WHERE posts.post_type IN ( 'product', 'product_variation' )
			AND wc_product_meta_lookup.stock_status = %s
			",
			$status
		)
	);
}