WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

ProductQueryFilters::generate_stock_status_count_query() private WC 1.0

Generate calculate query by stock status.

{} It's a method of the class: ProductQueryFilters{}

No Hooks.

Return

false|String.

Usage

// private - for code of main (parent) class only
$result = $this->generate_stock_status_count_query( $status, $product_query_sql, $stock_status_options );
$status(string) (required)
status to calculate.
$product_query_sql(string) (required)
product query for current filter state.
$stock_status_options(array) (required)
available stock status options.

Code of ProductQueryFilters::generate_stock_status_count_query() WC 5.8.0

private function generate_stock_status_count_query( $status, $product_query_sql, $stock_status_options ) {
	if ( ! in_array( $status, $stock_status_options, true ) ) {
		return false;
	}
	global $wpdb;
	$status = esc_sql( $status );
	return "
		SELECT COUNT( DISTINCT posts.ID ) as status_count
		FROM {$wpdb->posts} as posts
		INNER JOIN {$wpdb->postmeta} as postmeta ON posts.ID = postmeta.post_id
            AND postmeta.meta_key = '_stock_status'
            AND postmeta.meta_value = '{$status}'
		WHERE posts.ID IN ( {$product_query_sql} )
	";
}