term_id; $term = new Timber\Term($term_id); $has_sub_cats = ($term->children) ? true : false; if ($has_sub_cats) { $context['sub_cats'] = $term->children; $template = 'woocommerce/archive-cat.twig'; } else { global $wp_query; /* $products_args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, ); */ $currentTerm = false; $current_filter = "-"; if (!empty($_GET['product_tag'])) { $currentTerm = get_term_by('slug', $_GET['product_tag'], 'product_tag'); $current_filter = $currentTerm->slug; } if (!empty($currentTerm)) { $tax = [ 'taxonomy' => 'product_tag', 'field' => 'term_id', //This is optional, as it defaults to 'term_id' 'terms' => $currentTerm->term_id, 'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'. ]; $products_args['tax_query'] = [$tax]; $wp_query->set('tax_query', $tax); } $posts = Timber::get_posts(); $context['products'] = $posts; $filters = Timber::get_terms(array( 'taxonomy' => 'product_tag', 'hide_empty' => false, )); $context['filters'] = $filters; $context['current_filter'] = $current_filter; // cat routine $current_cat_routine = []; if( !empty($context['options']['cat_routine_items']) ){ $cat_routine_items = $context['options']['cat_routine_items']; foreach( $cat_routine_items as $cat_routine ){ foreach( $cat_routine['step_items'] as $key => $step ){ if( in_array($term->id, $step['cat'] ) ){ $step['index'] = (string) $key; $current_cat_routine = array( 'steps' => $cat_routine['step_items'], 'active' => $step, 'active_index' => $key ); } } } $context['cat_routine'] = $current_cat_routine; } $template = 'woocommerce/archive-product.twig'; } //$context['category'] = get_term( $term_id, 'product_cat' ); $context['page']['title'] = $term->name; $context['page']['thumbnail'] = $term->thumbnail_id; $context['page']['excerpt'] = $term->description; $context['term'] = $term; $context['wp_nonce'] = wp_create_nonce('wc_store_api'); } else if (is_post_type_archive('product')) { $template = 'woocommerce/archive-cat.twig'; $shop_page_id = wc_get_page_id('shop'); $context['page'] = new Timber\Post($shop_page_id); $context['is_shop_archive_product'] = true; } Website::render($template, $context);