Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::get_filter_by_stock_status_query()privateWC 1.0

Return a query that filters products by stock status.

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

Хуков нет.

Возвращает

Массив.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_filter_by_stock_status_query();

Код ProductQuery::get_filter_by_stock_status_query() WC 7.3.0

private function get_filter_by_stock_status_query() {
	$filter_stock_status_values = get_query_var( StockFilter::STOCK_STATUS_QUERY_VAR );

	if ( empty( $filter_stock_status_values ) ) {
		return array();
	}

	$filtered_stock_status_values = array_filter(
		explode( ',', $filter_stock_status_values ),
		function( $stock_status ) {
			return in_array( $stock_status, StockFilter::get_stock_status_query_var_values(), true );
		}
	);

	if ( empty( $filtered_stock_status_values ) ) {
		return array();
	}

	return array(
		// Ignoring the warning of not using meta queries.
		// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
		'meta_query' => array(
			array(
				'key'      => '_stock_status',
				'value'    => $filtered_stock_status_values,
				'operator' => 'IN',

			),
		),
	);
}