Automattic\WooCommerce\Blocks\BlockTypes

ProductCollection::get_date_query()privateWC 1.0

Constructs a date query for product filtering based on a specified time frame.

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

Хуков нет.

Возвращает

Массив. Date query array; empty if parameters are invalid.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_date_query( $time_frame ): array;
$time_frame(массив) (обязательный)

Associative array with 'operator' (in or not-in) and 'value' (date string).

  • operator(строка)
    Determines the inclusion or exclusion of the date range.

  • value(строка)
    The date around which the range is applied.

Код ProductCollection::get_date_query() WC 9.4.2

private function get_date_query( array $time_frame ): array {
	// Validate time_frame elements.
	if ( empty( $time_frame['operator'] ) || empty( $time_frame['value'] ) ) {
		return array();
	}

	// Determine the query operator based on the 'operator' value.
	$query_operator = 'in' === $time_frame['operator'] ? 'after' : 'before';

	// Construct and return the date query.
	return array(
		'date_query' => array(
			array(
				'column'        => 'post_date_gmt',
				$query_operator => $time_frame['value'],
				'inclusive'     => true,
			),
		),
	);
}