Esempio n. 1
0
 function widget($args, $instance)
 {
     if (get_integration_type() != 'simple') {
         if (!empty($instance['shortcode_support']) && has_show_products_shortcode() || (is_ic_taxonomy_page() || is_ic_product_listing())) {
             $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
             $taxonomy = get_current_screen_tax();
             if (is_ic_taxonomy_page() && !is_product_filter_active('product_category')) {
                 $categories = get_terms($taxonomy, array('parent' => get_queried_object()->term_id));
             } else {
                 if (!empty($instance['shortcode_support']) && !is_ic_product_listing() && has_show_products_shortcode()) {
                     global $shortcode_query;
                     $parent = isset($shortcode_query->query_vars['term_id']) ? $shortcode_query->query_vars['term_id'] : 0;
                     $categories = get_terms($taxonomy, array('parent' => $parent));
                 } else {
                     $categories = get_terms($taxonomy, array('parent' => 0));
                 }
             }
             $form = '';
             $child_form = '';
             foreach ($categories as $category) {
                 $form .= get_product_category_filter_element($category);
             }
             $class = 'product-category-filter-container';
             if (is_product_filter_active('product_category')) {
                 $class .= ' filter-active';
                 $filter_value = get_product_filter_value('product_category');
                 $children = get_terms($taxonomy, array('parent' => $filter_value));
                 //if ( !is_ic_taxonomy_page() ) {
                 $parent_term = get_term_by('id', $filter_value, $taxonomy);
                 if (!empty($parent_term->parent)) {
                     $form .= get_product_category_filter_element($parent_term);
                 }
                 //}
                 if (is_array($children)) {
                     foreach ($children as $child) {
                         $child_form .= get_product_category_filter_element($child);
                     }
                 }
             }
             if (!empty($form) || !empty($child_form)) {
                 echo $args['before_widget'];
                 if ($title) {
                     echo $args['before_title'] . $title . $args['after_title'];
                 }
                 echo '<div class="' . $class . '">';
                 echo $form;
                 if (!empty($child_form)) {
                     echo '<div class="child-category-filters">' . $child_form . '</div>';
                 }
                 echo '</div>';
                 echo $args['after_widget'];
             }
         }
     }
 }
Esempio n. 2
0
/**
 * Applies product price filter to shortcode query
 * @param type $shortcode_query
 * @return string
 */
function apply_product_price_filter($shortcode_query)
{
    if (is_product_filter_active('min-price') || is_product_filter_active('max-price')) {
        $metaquery = array();
        $min_price = get_product_filter_value('min-price');
        if (!empty($min_price)) {
            $metaquery[] = array('key' => '_price', 'compare' => '>=', 'value' => $min_price, 'type' => 'NUMERIC');
        }
        $max_price = get_product_filter_value('max-price');
        if (!empty($max_price)) {
            $metaquery[] = array('key' => '_price', 'compare' => '<=', 'value' => $max_price, 'type' => 'NUMERIC');
        }
        $shortcode_query['meta_query'] = $metaquery;
    }
    return $shortcode_query;
}