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
/**
 * Returns realted products
 *
 * @global object $post
 * @param int $products_limit
 * @param boolean $markup
 * @return string
 */
function get_related_products($products_limit = null, $markup = false)
{
    if (!isset($products_limit)) {
        $products_limit = get_current_per_row();
    }
    $current_product_id = get_the_ID();
    $taxonomy = get_current_screen_tax();
    $post_type = get_current_screen_post_type();
    $terms = get_the_terms($current_product_id, $taxonomy);
    if (is_array($terms) && !empty($taxonomy) && !empty($post_type)) {
        $terms = array_reverse($terms);
        $archive_template = get_product_listing_template();
        $i = 0;
        $inside = '';
        $products = array();
        foreach ($terms as $term) {
            $query_param = array('post_type' => $post_type, 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $term->slug)), 'posts_per_page' => $products_limit);
            $query = new WP_Query($query_param);
            while ($query->have_posts()) {
                $query->the_post();
                global $post;
                if ($current_product_id != $post->ID) {
                    $i++;
                    $products[] = $post->ID;
                }
                if ($i >= $products_limit) {
                    break;
                }
            }
            wp_reset_postdata();
            reset_row_class();
            if ($i >= $products_limit) {
                break;
            }
        }
        $div = '';
        if (!empty($products)) {
            $products = implode(',', $products);
            if ($markup) {
                $div = '<div class="related-products">';
                $single_names = get_single_names();
                if (!empty($single_names['other_categories'])) {
                    $div .= '<h2 class="catalog-header">' . $single_names['other_categories'] . '</h2>';
                }
                $div .= do_shortcode('[show_products product="' . $products . '"]');
                $div .= '</div>';
            } else {
                $div = do_shortcode('[show_products product="' . $products . '"]');
            }
        }
        return $div;
    }
    return;
}
Esempio n. 3
0
/**
 * Returns category product count with product in child categories
 *
 * @param type $cat_id
 * @return type
 */
function total_product_category_count($cat_id)
{
    $taxonomy = get_current_screen_tax();
    $query_args = apply_filters('category_count_query', array('nopaging' => true, 'tax_query' => array(array('taxonomy' => $taxonomy, 'terms' => $cat_id, 'include_children' => true)), 'fields' => 'ids'));
    if (isset($_GET['s'])) {
        $query_args['s'] = $_GET['s'];
    }
    $q = new WP_Query($query_args);
    return $q->post_count;
}