Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_stock_status_query()privateWC 1.0

Return a query for products depending on their stock status.

Метод класса: ProductQuery{}

Хуков нет.

Возвращает

Массив.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_stock_status_query( $stock_statii );
$stock_statii(массив) (обязательный)
An array of acceptable stock statii.

Код ProductQuery::get_stock_status_query() WC 8.9.3

private function get_stock_status_query( $stock_statii ) {
	if ( ! is_array( $stock_statii ) ) {
		return array();
	}

	$stock_status_options = array_keys( wc_get_product_stock_status_options() );

	/**
	 * If all available stock status are selected, we don't need to add the
	 * meta query for stock status.
	 */
	if (
		count( $stock_statii ) === count( $stock_status_options ) &&
		array_diff( $stock_statii, $stock_status_options ) === array_diff( $stock_status_options, $stock_statii )
	) {
		return array();
	}

	/**
	 * If all stock statuses are selected except 'outofstock', we use the
	 * product visibility query to filter out out of stock products.
	 *
	 * @see get_product_visibility_query()
	 */
	$diff = array_diff( $stock_status_options, $stock_statii );
	if ( count( $diff ) === 1 && in_array( 'outofstock', $diff, true ) ) {
		return array();
	}

	return array(
		'meta_query' => array(
			array(
				'key'     => '_stock_status',
				'value'   => (array) $stock_statii,
				'compare' => 'IN',
			),
		),
	);
}