/** * Show widget to user * * @param array $args * @param array $instance */ function widget($args, $instance) { $br_options = apply_filters('berocket_aapf_listener_br_options', get_option('br_filters_options')); if (@$br_options['filters_turn_off']) { return false; } global $wp_query, $wp; wp_register_style('berocket_aapf_widget-style', plugins_url('../css/widget.css', __FILE__)); wp_enqueue_style('berocket_aapf_widget-style'); /* custom scrollbar */ wp_enqueue_script('berocket_aapf_widget-scroll-script', plugins_url('../js/scrollbar/Scrollbar.concat.min.js', __FILE__), array('jquery')); wp_register_style('berocket_aapf_widget-scroll-style', plugins_url('../css/scrollbar/Scrollbar.min.css', __FILE__)); wp_enqueue_style('berocket_aapf_widget-scroll-style'); /* main scripts */ wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-slider'); wp_enqueue_script('berocket_aapf_widget-script', plugins_url('../js/widget.min.js', __FILE__), array('jquery')); wp_enqueue_script('berocket_aapf_widget-hack-script', plugins_url('../js/mobiles.min.js', __FILE__), array('jquery')); $wp_query_product_cat = '-1'; if (@$wp_query->query['product_cat']) { $wp_query_product_cat = explode("/", $wp_query->query['product_cat']); $wp_query_product_cat = $wp_query_product_cat[count($wp_query_product_cat) - 1]; } if (!$br_options['products_holder_id']) { $br_options['products_holder_id'] = 'ul.products'; } $post_temrs = "[]"; if (@$_POST['terms']) { $post_temrs = @json_encode($_POST['terms']); } wp_localize_script('berocket_aapf_widget-script', 'the_ajax_script', array('current_page_url' => preg_replace("~paged?/[0-9]+/?~", "", home_url($wp->request)), 'ajaxurl' => admin_url('admin-ajax.php'), 'product_cat' => $wp_query_product_cat, 'products_holder_id' => $br_options['products_holder_id'], 'control_sorting' => $br_options['control_sorting'], 'seo_friendly_urls' => $br_options['seo_friendly_urls'], 'berocket_aapf_widget_product_filters' => $post_temrs, 'user_func' => @$br_options['user_func'])); extract($args); extract($instance); if ($widget_type == 'update_button') { set_query_var('title', apply_filters('berocket_aapf_widget_title', $title)); br_get_template_part('widget_update_button'); return ''; } $product_cat = @json_decode($product_cat); if ($product_cat) { $hide_widget = true; $cur_cat = get_term_by('slug', $wp_query_product_cat, 'product_cat'); $cur_cat_ancestors = get_ancestors($cur_cat->term_id, 'product_cat'); $cur_cat_ancestors[] = $cur_cat->term_id; if ($product_cat) { if ($cat_propagation) { foreach ($product_cat as $cat) { $cat = get_term_by('slug', $cat, 'product_cat'); if (@in_array($cat->term_id, $cur_cat_ancestors)) { $hide_widget = false; } } } else { foreach ($product_cat as $cat) { if ($cat == $wp_query_product_cat) { $hide_widget = false; } } } } if ($hide_widget) { return true; } } $woocommerce_hide_out_of_stock_items = BeRocket_AAPF_Widget::woocommerce_hide_out_of_stock_items(); $terms = $sort_terms = $price_range = array(); if ($attribute == 'price') { $price_range = BeRocket_AAPF_Widget::get_price_range($wp_query_product_cat, $woocommerce_hide_out_of_stock_items); if (!$price_range or count($price_range) < 2) { return false; } } else { $sort_array = array(); $wc_order_by = wc_attribute_orderby($attribute); if (@$br_options['show_all_values']) { $terms = BeRocket_AAPF_Widget::get_attribute_values($attribute); } else { $terms = BeRocket_AAPF_Widget::get_attribute_values($attribute, 'id', true); } if (@count($terms) < 2) { return false; } if ($wc_order_by == 'menu_order') { foreach ($terms as $term) { $sort_array[] = get_woocommerce_term_meta($term->term_id, 'order_' . $attribute); } array_multisort($sort_array, $terms); } elseif ($wc_order_by == 'name' or $wc_order_by == 'name_num') { foreach ($terms as $term) { $sort_array[] = $term->name; } $sort_as = SORT_STRING; if ($wc_order_by == 'name_num') { $sort_as = SORT_NUMERIC; } array_multisort($sort_array, $terms, SORT_ASC, $sort_as); } set_query_var('terms', apply_filters('berocket_aapf_widget_terms', $terms)); } $style = $class = ''; if (@$height and $height != 'auto') { $style = "style='height: {$height}px; overflow: hidden;'"; $class = "berocket_aapf_widget_height_control"; } if (!$scroll_theme) { $scroll_theme = 'dark'; } set_query_var('operator', $operator); set_query_var('title', apply_filters('berocket_aapf_widget_title', $title)); set_query_var('class', apply_filters('berocket_aapf_widget_class', $class)); set_query_var('css_class', apply_filters('berocket_aapf_widget_css_class', $css_class)); set_query_var('style', apply_filters('berocket_aapf_widget_style', $style)); set_query_var('scroll_theme', $scroll_theme); set_query_var('x', time()); // widget title and start tag ( <ul> ) can be found in templates/widget_start.php br_get_template_part('widget_start'); if ($type == 'slider') { $min = $max = false; $main_class = 'slider'; $slider_class = 'berocket_filter_slider'; if ($attribute == 'price') { if ($price_range) { foreach ($price_range as $price) { if ($min === false or $min > (int) $price) { $min = $price; } if ($max === false or $max < (int) $price) { $max = $price; } } } $id = rand(0, time()); $slider_class .= ' berocket_filter_price_slider'; $main_class .= ' price'; $min = number_format(floor($min), 2, '.', ''); $max = number_format(ceil($max), 2, '.', ''); } else { if ($terms) { foreach ($terms as $term) { if ($min === false or $min > (int) $term->slug) { $min = $term->slug; } if ($max === false or $max < (int) $term->slug) { $max = $term->slug; } } } $id = $term->taxonomy; } $slider_value1 = $min; $slider_value2 = $max; if ($attribute == 'price' and @$_POST['price']) { $slider_value1 = $_POST['price'][0]; $slider_value2 = $_POST['price'][1]; } if ($attribute != 'price' and @$_POST['limits']) { foreach ($_POST['limits'] as $p_limit) { if ($p_limit[0] == $attribute) { $slider_value1 = $p_limit[1]; $slider_value2 = $p_limit[2]; } } } set_query_var('slider_value1', $slider_value1); set_query_var('slider_value2', $slider_value2); set_query_var('filter_slider_id', $id); set_query_var('main_class', $main_class); set_query_var('slider_class', $slider_class); set_query_var('min', $min); set_query_var('max', $max); } br_get_template_part($type); br_get_template_part('widget_end'); }