WC_Shortcode_Products::set_categories_query_args() protected WC 3.2.0
Set categories query args.
{} Это метод класса: WC_Shortcode_Products{}
Хуков нет.
Возвращает
Null. Ничего.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->set_categories_query_args( $query_args );
- $query_args(массив) (обязательный) (передается по ссылке — &)
- Query args.
Список изменений
С версии 3.2.0 | Введена. |
Код WC_Shortcode_Products::set_categories_query_args() WC Shortcode Products::set categories query args WC 5.0.0
protected function set_categories_query_args( &$query_args ) {
if ( ! empty( $this->attributes['category'] ) ) {
$categories = array_map( 'sanitize_title', explode( ',', $this->attributes['category'] ) );
$field = 'slug';
if ( is_numeric( $categories[0] ) ) {
$field = 'term_id';
$categories = array_map( 'absint', $categories );
// Check numeric slugs.
foreach ( $categories as $cat ) {
$the_cat = get_term_by( 'slug', $cat, 'product_cat' );
if ( false !== $the_cat ) {
$categories[] = $the_cat->term_id;
}
}
}
$query_args['tax_query'][] = array(
'taxonomy' => 'product_cat',
'terms' => $categories,
'field' => $field,
'operator' => $this->attributes['cat_operator'],
/*
* When cat_operator is AND, the children categories should be excluded,
* as only products belonging to all the children categories would be selected.
*/
'include_children' => 'AND' === $this->attributes['cat_operator'] ? false : true,
);
}
}