__('Filter woocommerce products by price.', 'wchweb')) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) { return; } global $wchweb; // price range for filtered products $filtered_price_range = $wchweb->getPriceRange(true); // price range for all published products $unfiltered_price_range = $wchweb->getPriceRange(false); $html = ''; // to be sure that these values are number $min_val = $max_val = 0; if (sizeof($unfiltered_price_range) === 2) { $min_val = $unfiltered_price_range[0]; $max_val = $unfiltered_price_range[1]; } // display type, slider or list $display_type = $instance['display_type']; // required scripts // enqueue necessary scripts wp_enqueue_style('wchweb-style'); wp_enqueue_style('font-awesome'); wp_enqueue_script('wchweb-script'); if ($display_type === 'slider') { wp_enqueue_script('wchweb-nouislider-script'); wp_enqueue_script('wchweb-price-filter-script'); wp_enqueue_style('wchweb-nouislider-style'); // get values from url $set_min_val = null; if (isset($_GET['min-price']) && !empty($_GET['min-price'])) { $set_min_val = (int)$_GET['min-price']; } $set_max_val = null; if (isset($_GET['max-price']) && !empty($_GET['max-price'])) { $set_max_val = (int)$_GET['max-price']; } } else { $price_lists = $instance['price_list']; $show_currency = $instance['show_currency']; $currency_symbol = get_woocommerce_currency_symbol(); $currency_position = get_option('woocommerce_currency_pos'); } // HTML markup for price slider // Slider markup if ($display_type === 'slider') { $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '

' . __('Min Price', 'wchweb') . ':

'; $html .= '

' . __('Max Price', 'wchweb') . ':

'; $html .= '
'; $html .= '
'; } // List markup elseif ($display_type === 'list') { //echo '
'; print_r($show_currency);die;

				$html .= '
'; $html .= ''; $html .= '
'; } extract($args); // Add class to before_widget from within a custom widget // http://wordpress.stackexchange.com/questions/18942/add-class-to-before-widget-from-within-a-custom-widget if ($display_type === 'slider') { $widget_class = 'woocommerce wchweb-price-filter-widget'; } else { $widget_class = 'woocommerce wchweb-price-filter-widget wchweb-ajax-term-filter'; } // no class found, so add it if (strpos($before_widget, 'class') === false) { $before_widget = str_replace('>', 'class="' . $widget_class . '"', $before_widget); } // class found but not the one that we need, so add it else { $before_widget = str_replace('class="', 'class="' . $widget_class . ' ', $before_widget); } echo $before_widget; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']). $args['after_title']; } echo $html; echo $args['after_widget']; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form($instance) { ?>

>

×

×

$mmin) { $mmin = intval($mmin); $mmax = intval($max[$key]); $mto = !empty($to[$key]) ? $to[$key] : '-'; if (isset($mmin) && !empty($mmax)) { $price_list[] = array( 'min' => $mmin, 'to' => $mto, 'max' => $mmax, ); } } $instance['price_list'] = $price_list; } return $instance; } } } // register widget if (!function_exists('wchweb_register_price_filter_widget')) { function wchweb_register_price_filter_widget() { register_widget('WCHWEB_Price_Filter_Widget'); } add_action('widgets_init', 'wchweb_register_price_filter_widget'); }