WC_Query::get_layered_nav_chosen_attributes()public staticWC 1.0

Get an array of attributes and terms selected with the layered nav widget.

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

Хуки из метода

Возвращает

Массив.

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

$result = WC_Query::get_layered_nav_chosen_attributes();

Код WC_Query::get_layered_nav_chosen_attributes() WC 8.7.0

public static function get_layered_nav_chosen_attributes() {
	// phpcs:disable WordPress.Security.NonceVerification.Recommended
	if ( ! is_array( self::$chosen_attributes ) ) {
		self::$chosen_attributes = array();

		if ( ! empty( $_GET ) ) {
			foreach ( $_GET as $key => $value ) {
				if ( 0 === strpos( $key, 'filter_' ) ) {
					$attribute    = wc_sanitize_taxonomy_name( str_replace( 'filter_', '', $key ) );
					$taxonomy     = wc_attribute_taxonomy_name( $attribute );
					$filter_terms = ! empty( $value ) ? explode( ',', wc_clean( wp_unslash( $value ) ) ) : array();

					if ( empty( $filter_terms ) || ! taxonomy_exists( $taxonomy ) || ! wc_attribute_taxonomy_id_by_name( $attribute ) ) {
						continue;
					}

					$query_type                                    = ! empty( $_GET[ 'query_type_' . $attribute ] ) && in_array( $_GET[ 'query_type_' . $attribute ], array( 'and', 'or' ), true ) ? wc_clean( wp_unslash( $_GET[ 'query_type_' . $attribute ] ) ) : '';
					self::$chosen_attributes[ $taxonomy ]['terms'] = array_map( 'sanitize_title', $filter_terms ); // Ensures correct encoding.
					self::$chosen_attributes[ $taxonomy ]['query_type'] = $query_type ? $query_type : apply_filters( 'woocommerce_layered_nav_default_query_type', 'and' );
				}
			}
		}
	}
	return self::$chosen_attributes;
	// phpcs:disable WordPress.Security.NonceVerification.Recommended
}