Skip to content

Instantly share code, notes, and snippets.

@WhiteHatJoker
Last active October 18, 2021 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WhiteHatJoker/ecc377391453a45603c7c6014e52c680 to your computer and use it in GitHub Desktop.
Save WhiteHatJoker/ecc377391453a45603c7c6014e52c680 to your computer and use it in GitHub Desktop.
If you have installed the Woocommerce Products Filter (woof) plugin and you have custom page that you would like your users to return when they press the reset button no matter where they are, please follow my instructions. Keep in mind: Permalinks are turned on.

Woof reset button action

If you have installed the Woocommerce Products Filter (woof) plugin and you have custom page that you would like your users to return when they press the reset button no matter where they are, please follow my instructions. Keep in mind: Permalinks are turned on.

Instructions

  1. You need to have the woof plugin installed or downloaded.
  2. Download current repository and place the contents within woof plugin directory overwriting changes.
  3. Open views/woof.php and replace the http://your_link on line 479 data-link="http://your_link" with your url where you would like your users to go when they hit refresh.
  4. Enjoy!

Note

It worked with WooCommerce Products Filter version 2.1.5.1, so if you just want to know the changes made to the original plugin files, look at the previous commit history of respective files.

var woof_redirect = '';//if we use redirect attribute in shortcode [woof]
//***
jQuery(function () {
jQuery('body').append('<div id="woof_html_buffer" class="woof_info_popup" style="display: none;"></div>');
jQuery.fn.life = function (types, data, fn) {
jQuery(this.context).on(types, this.selector, data, fn);
return this;
};
//http://stackoverflow.com/questions/2389540/jquery-hasparent
jQuery.extend(jQuery.fn, {
within: function (pSelector) {
// Returns a subset of items using jQuery.filter
return this.filter(function () {
// Return truthy/falsey based on presence in parent
return jQuery(this).closest(pSelector).length;
});
}
});
//+++
if (jQuery('#woof_results_by_ajax').length > 0) {
woof_is_ajax = 1;
}
//listening attributes in shortcode [woof]
woof_autosubmit = parseInt(jQuery('.woof').eq(0).data('autosubmit'), 10);
woof_ajax_redraw = parseInt(jQuery('.woof').eq(0).data('ajax-redraw'), 10);
//+++
woof_ext_init_functions = jQuery.parseJSON(woof_ext_init_functions);
//fix for native woo price range
woof_init_native_woo_price_filter();
jQuery('body').bind('price_slider_change', function (event, min, max) {
if (woof_autosubmit && !woof_show_price_search_button) {
jQuery('.widget_price_filter form').trigger('submit');
} else {
var min_price = jQuery(this).find('.price_slider_amount #min_price').val();
var max_price = jQuery(this).find('.price_slider_amount #max_price').val();
woof_current_values.min_price = min_price;
woof_current_values.max_price = max_price;
}
});
jQuery('.woof_price_filter_dropdown').life('change', function () {
var val = jQuery(this).val();
if (parseInt(val, 10) == -1) {
delete woof_current_values.min_price;
delete woof_current_values.max_price;
} else {
var val = val.split("-");
woof_current_values.min_price = val[0];
woof_current_values.max_price = val[1];
}
if (woof_autosubmit || jQuery(this).within('.woof').length == 0) {
woof_submit_link(woof_get_submit_link());
}
});
//ion-slider price range slider
woof_init_ion_sliders();
//***
woof_init_show_auto_form();
woof_init_hide_auto_form();
//***
woof_remove_empty_elements();
woof_init_search_form();
woof_init_pagination();
woof_init_orderby();
woof_init_reset_button();
woof_init_beauty_scroll();
//+++
woof_draw_products_top_panel();
woof_shortcode_observer();
//+++
//if we use redirect attribute in shortcode [woof is_ajax=0]
//not for ajax, for redirect mode only
if (!woof_is_ajax) {
woof_redirect_init();
}
woof_init_toggles();
});
//if we use redirect attribute in shortcode [woof is_ajax=0]
//not for ajax, for redirect mode only
function woof_redirect_init() {
try {
if (jQuery('.woof').length) {
//https://wordpress.org/support/topic/javascript-error-in-frontjs?replies=1
if (undefined !== jQuery('.woof').val()) {
woof_redirect = jQuery('.woof').eq(0).data('redirect');//default value
if (woof_redirect.length > 0) {
woof_shop_page = woof_current_page_link = woof_redirect;
}
//***
/*
var events = ['click', 'change', 'ifChecked', 'ifUnchecked'];
for (var i = 0; i < events.length; i++) {
jQuery('div.woof input, div.woof option, div.woof div, div.woof label').live(events[i], function (e) {
try {
if (jQuery(this).parents('.woof').data('redirect').length > 0) {
woof_redirect = jQuery(this).parents('.woof').data('redirect');
}
} catch (e) {
console.log('Error: attribute redirection doesn works!');
}
e.stopPropagation();
});
}
*/
//***
return woof_redirect;
}
}
} catch (e) {
console.log(e);
}
}
function woof_init_orderby() {
jQuery('form.woocommerce-ordering').life('submit', function () {
return false;
});
jQuery('form.woocommerce-ordering select.orderby').life('change', function () {
woof_current_values.orderby = jQuery(this).val();
woof_ajax_page_num = 1;
woof_submit_link(woof_get_submit_link());
return false;
});
}
function woof_init_reset_button() {
jQuery('.woof_reset_search_form').life('click', function () {
var link = jQuery(this).data('link');
woof_ajax_page_num = 1;
if (woof_is_permalink) {
woof_current_values = {};
//woof_submit_link(woof_get_submit_link().split("page/")[0]);
woof_submit_link(link);
//woof_submit_link(woof_get_submit_link());
} else {
var link = woof_shop_page;
if (woof_current_values.hasOwnProperty('page_id')) {
link = location.protocol + '//' + location.host + "/?page_id=" + woof_current_values.page_id;
woof_current_values = {'page_id': woof_current_values.page_id};
woof_get_submit_link();
}
//***
woof_submit_link(link);
if (woof_is_ajax) {
history.pushState({}, "", link);
if (woof_current_values.hasOwnProperty('page_id')) {
woof_current_values = {'page_id': woof_current_values.page_id};
} else {
woof_current_values = {};
}
}
}
return false;
});
}
function woof_init_pagination() {
if (woof_is_ajax === 1) {
//jQuery('.woocommerce-pagination ul.page-numbers a.page-numbers').life('click', function () {
jQuery('a.page-numbers').life('click', function () {
var l = jQuery(this).attr('href');
if (woof_ajax_first_done) {
//http://woocommerce-filter.pluginus.net/wp-admin/admin-ajax.php?paged=2
var res = l.split("paged=");
if (typeof res[1] !== 'undefined') {
woof_ajax_page_num = parseInt(res[1]);
} else {
woof_ajax_page_num = 1;
}
} else {
//http://woocommerce-filter.pluginus.net/tester/page/2/
var res = l.split("page/");
if (typeof res[1] !== 'undefined') {
woof_ajax_page_num = parseInt(res[1]);
} else {
woof_ajax_page_num = 1;
}
}
//+++
//if (woof_autosubmit) - pagination doesn need pressing any submit button!!
{
woof_submit_link(woof_get_submit_link());
}
return false;
});
}
}
function woof_init_search_form() {
woof_init_checkboxes();
woof_init_mselects();
woof_init_radios();
woof_init_selects();
//for extensions
if (woof_ext_init_functions !== null) {
jQuery.each(woof_ext_init_functions, function (type, func) {
eval(func + '()');
});
}
//+++
//var containers = jQuery('.woof_container');
//+++
jQuery('.woof_submit_search_form').click(function () {
if (woof_ajax_redraw) {
//[woof redirect="http://www.dev.woocommerce-filter.com/test-all/" autosubmit=1 ajax_redraw=1 is_ajax=1 tax_only="locations" by_only="none"]
woof_ajax_redraw = 0;
woof_is_ajax = 0;
}
//***
woof_submit_link(woof_get_submit_link());
return false;
});
//***
jQuery('ul.woof_childs_list').parent('li').addClass('woof_childs_list_li');
//***
woof_remove_class_widget();
woof_checkboxes_slide();
}
function woof_submit_link(link) {
woof_show_info_popup(woof_lang_loading);
if (woof_is_ajax === 1 && !woof_ajax_redraw) {
woof_ajax_first_done = true;
var data = {
action: "woof_draw_products",
link: link,
page: woof_ajax_page_num,
shortcode: jQuery('#woof_results_by_ajax').data('shortcode'),
woof_shortcode: jQuery('div.woof').data('shortcode')
};
jQuery.post(woof_ajaxurl, data, function (content) {
content = jQuery.parseJSON(content);
if (jQuery('.woof_results_by_ajax_shortcode').length) {
jQuery('#woof_results_by_ajax').replaceWith(content.products);
} else {
jQuery('.woof_shortcode_output').replaceWith(content.products);
}
jQuery('div.woof_redraw_zone').replaceWith(jQuery(content.form).find('.woof_redraw_zone'));
woof_remove_empty_elements();
woof_init_search_form();
woof_hide_info_popup();
woof_draw_products_top_panel();
woof_init_beauty_scroll();
woof_init_ion_sliders();
woof_reinit_native_woo_price_filter();//native woo price range slider reinit
//removing id woof_results_by_ajax - multi in ajax mode sometimes
//when uses shorcode woof_products in ajax and in settings try ajaxify shop is Yes
jQuery.each(jQuery('#woof_results_by_ajax'), function (index, item) {
if (index == 0) {
return;
}
jQuery(item).removeAttr('id');
});
//*** script after ajax loading here
woof_js_after_ajax_done();
});
} else {
if (woof_ajax_redraw) {
//redrawing [woof ajax_redraw=1] only
var data = {
action: "woof_draw_products",
link: link,
page: 1,
shortcode: 'woof_nothing', //we do not need get any products, serach form data only
woof_shortcode: jQuery('div.woof').eq(0).data('shortcode')
};
jQuery.post(woof_ajaxurl, data, function (content) {
content = jQuery.parseJSON(content);
jQuery('div.woof_redraw_zone').replaceWith(jQuery(content.form).find('.woof_redraw_zone'));
woof_remove_empty_elements();
woof_init_search_form();
woof_hide_info_popup();
woof_init_beauty_scroll();
woof_init_ion_sliders();
woof_reinit_native_woo_price_filter();//native woo price range slider reinit
});
} else {
window.location = link;
}
}
}
function woof_remove_empty_elements() {
// lets check for empty drop-downs
jQuery.each(jQuery('.woof_container select'), function (index, select) {
var size = jQuery(select).find('option').size();
if (size === 0) {
jQuery(select).parents('.woof_container').remove();
}
});
//+++
// lets check for empty checkboxes, radio, color conatiners
jQuery.each(jQuery('ul.woof_list'), function (index, ch) {
var size = jQuery(ch).find('li').size();
if (size === 0) {
jQuery(ch).parents('.woof_container').remove();
}
});
}
function woof_get_submit_link() {
//filter woof_current_values values
if (woof_is_ajax) {
woof_current_values.page = woof_ajax_page_num;
}
//+++
if (Object.keys(woof_current_values).length > 0) {
jQuery.each(woof_current_values, function (index, value) {
if (index == swoof_search_slug) {
delete woof_current_values[index];
}
if (index == 's') {
delete woof_current_values[index];
}
if (index == 'product') {
//for single product page (when no permalinks)
delete woof_current_values[index];
}
if (index == 'really_curr_tax') {
delete woof_current_values[index];
}
});
}
//***
if (Object.keys(woof_current_values).length === 2) {
if (('min_price' in woof_current_values) && ('max_price' in woof_current_values)) {
var l = woof_current_page_link + '?min_price=' + woof_current_values.min_price + '&max_price=' + woof_current_values.max_price;
if (woof_is_ajax) {
history.pushState({}, "", l);
}
return l;
}
}
//***
if (Object.keys(woof_current_values).length === 0) {
if (woof_is_ajax) {
history.pushState({}, "", woof_current_page_link);
}
return woof_current_page_link;
}
//+++
if (Object.keys(woof_really_curr_tax).length > 0) {
woof_current_values['really_curr_tax'] = woof_really_curr_tax.term_id + '-' + woof_really_curr_tax.taxonomy;
}
//+++
var link = woof_current_page_link + "?" + swoof_search_slug + "=1";
//console.log(woof_current_page_link);
//just for the case when no permalinks enabled
if (!woof_is_permalink) {
if (woof_redirect.length > 0) {
link = woof_redirect + "?" + swoof_search_slug + "=1";
if (woof_current_values.hasOwnProperty('page_id')) {
delete woof_current_values.page_id;
}
} else {
link = location.protocol + '//' + location.host + "?" + swoof_search_slug + "=1";
/*
if (!woof_is_ajax) {
link = location.protocol + '//' + location.host + "?" + swoof_search_slug + "=1";
}
if (woof_current_values.hasOwnProperty('page_id')) {
link = location.protocol + '//' + location.host + "?" + swoof_search_slug + "=1";
}
*/
}
}
//console.log(link);
//throw('STOP!');
//any trash for different sites, useful for quick support
var woof_exclude_accept_array = ['path'];
if (Object.keys(woof_current_values).length > 0) {
jQuery.each(woof_current_values, function (index, value) {
if (index == 'page' && woof_is_ajax) {
index = 'paged';//for right pagination if copy/paste this link and send somebody another by email for example
}
//http://www.dev.woocommerce-filter.com/?swoof=1&woof_author=3&woof_sku&woof_text=single
//avoid links where values is empty
if (typeof value !== 'undefined') {
if ((typeof value && value.length > 0) || typeof value == 'number')
{
if (jQuery.inArray(index, woof_exclude_accept_array) == -1) {
link = link + "&" + index + "=" + value;
}
}
}
});
}
//+++
//remove wp pagination like 'page/2'
link = link.replace(new RegExp(/page\/(\d+)\//), "");
if (woof_is_ajax) {
history.pushState({}, "", link);
}
//throw ("STOP!");
return link;
}
function woof_show_info_popup(text) {
if (woof_overlay_skin == 'default') {
jQuery("#woof_html_buffer").text(text);
jQuery("#woof_html_buffer").fadeTo(200, 0.9);
} else {
//http://jxnblk.com/loading/
switch (woof_overlay_skin) {
case 'loading-balls':
case 'loading-bars':
case 'loading-bubbles':
case 'loading-cubes':
case 'loading-cylon':
case 'loading-spin':
case 'loading-spinning-bubbles':
case 'loading-spokes':
jQuery('body').plainOverlay('show', {progress: function () {
return jQuery('<div id="woof_svg_load_container"><img style="height: 100%;width: 100%" src="' + woof_link + 'img/loading-master/' + woof_overlay_skin + '.svg" alt=""></div>');
}});
break;
default:
jQuery('body').plainOverlay('show', {duration: -1});
break;
}
}
}
function woof_hide_info_popup() {
if (woof_overlay_skin == 'default') {
window.setTimeout(function () {
jQuery("#woof_html_buffer").fadeOut(400);
}, 200);
} else {
jQuery('body').plainOverlay('hide');
}
}
function woof_draw_products_top_panel() {
if (jQuery('.woof_products_top_panel').length) {
if (woof_is_ajax) {
jQuery('#woof_results_by_ajax').prev('.woof_products_top_panel').remove();
}
var panel = jQuery('.woof_products_top_panel');
panel.html('');
if (Object.keys(woof_current_values).length > 0) {
panel.show();
panel.html('<ul></ul>');
var is_price_in = false;
//lets show this on the panel
jQuery.each(woof_current_values, function (index, value) {
//lets filter data for the panel
if (jQuery.inArray(index, woof_accept_array) == -1) {
return;
}
//***
if ((index == 'min_price' || index == 'max_price') && is_price_in) {
return;
}
if ((index == 'min_price' || index == 'max_price') && !is_price_in) {
is_price_in = true;
index = 'price';
value = woof_lang_pricerange;
}
//+++
value = value.toString().trim();
if (value.search(',')) {
value = value.split(',');
}
//+++
jQuery.each(value, function (i, v) {
if (index == 'page') {
return;
}
if (index == 'post_type') {
return;
}
var txt = v;
if (index == 'orderby') {
if (woof_lang[v] !== undefined) {
txt = woof_lang.orderby + ': ' + woof_lang[v];
} else {
txt = woof_lang.orderby + ': ' + v;
}
} else if (index == 'perpage') {
txt = woof_lang.perpage;
} else if (index == 'price') {
txt = woof_lang.pricerange;
} else {
var is_in_custom = false;
if (Object.keys(woof_lang_custom).length > 0) {
jQuery.each(woof_lang_custom, function (i, v) {
if (i == index) {
is_in_custom = true;
txt = v;
}
});
}
if (!is_in_custom) {
try {
//txt = jQuery('.woof_n_' + index + '_' + v).val();
txt = jQuery("input[data-anchor='woof_n_" + index + '_' + v + "']").val();
} catch (e) {
console.log(e);
}
if (typeof txt === 'undefined')
{
txt = v;
}
}
/* hidden feature
if (jQuery('input[name=woof_t_' + index + ']').length > 0) {
txt = jQuery('input[name=woof_t_' + index + ']').val() + ': ' + txt;
}
*/
}
panel.find('ul').append(
jQuery('<li>').append(
jQuery('<a>').attr('href', v).attr('data-tax', index).append(
jQuery('<span>').attr('class', 'woof_remove_ppi').append(txt)
)));
});
});
}
if (jQuery(panel).find('li').size() == 0) {
panel.hide();
}
//+++
panel.find('ul li a').click(function () {
var tax = jQuery(this).data('tax');
var name = jQuery(this).attr('href');
//***
if (tax != 'price') {
values = woof_current_values[tax];
values = values.split(',');
var tmp = [];
jQuery.each(values, function (index, value) {
if (value != name) {
tmp.push(value);
}
});
values = tmp;
if (values.length) {
woof_current_values[tax] = values.join(',');
} else {
delete woof_current_values[tax];
}
} else {
delete woof_current_values['min_price'];
delete woof_current_values['max_price'];
}
woof_ajax_page_num = 1;
//if (woof_autosubmit)
{
woof_submit_link(woof_get_submit_link());
}
jQuery('.woof_products_top_panel').find("[data-tax='" + tax + "'][href='" + name + "']").hide(333);
return false;
});
}
}
//control conditions if proucts shortcode uses on the page
function woof_shortcode_observer() {
if (jQuery('.woof_shortcode_output').length) {
woof_current_page_link = location.protocol + '//' + location.host + location.pathname;
}
if (jQuery('#woof_results_by_ajax').length) {
woof_is_ajax = 1;
}
}
function woof_init_beauty_scroll() {
if (woof_use_beauty_scroll) {
try {
jQuery(".woof_section_scrolled").mCustomScrollbar('destroy');
jQuery(".woof_section_scrolled").mCustomScrollbar({
scrollButtons: {
enable: true
},
advanced: {
updateOnContentResize: true,
updateOnBrowserResize: true
},
theme: "dark-2",
horizontalScroll: false,
mouseWheel: true,
scrollType: 'pixels',
contentTouchScroll: true
});
} catch (e) {
console.log(e);
}
}
}
//just for inbuilt price range widget
function woof_remove_class_widget() {
jQuery('.woof_container_inner').find('.widget').removeClass('widget');
}
function woof_init_show_auto_form() {
jQuery('.woof_show_auto_form').unbind('click');
jQuery('.woof_show_auto_form').click(function () {
var _this = this;
jQuery(_this).addClass('woof_hide_auto_form').removeClass('woof_show_auto_form');
jQuery(".woof_auto_show").show().animate(
{
height: (jQuery(".woof_auto_show_indent").height() + 20) + "px",
opacity: 1
}, 377, function () {
//jQuery(_this).text(woof_lang_hide_products_filter);
woof_init_hide_auto_form();
jQuery('.woof_auto_show').removeClass('woof_overflow_hidden');
jQuery('.woof_auto_show_indent').removeClass('woof_overflow_hidden');
jQuery(".woof_auto_show").height('auto');
});
return false;
});
}
function woof_init_hide_auto_form() {
jQuery('.woof_hide_auto_form').unbind('click');
jQuery('.woof_hide_auto_form').click(function () {
var _this = this;
jQuery(_this).addClass('woof_show_auto_form').removeClass('woof_hide_auto_form');
jQuery(".woof_auto_show").show().animate(
{
height: "1px",
opacity: 0
}, 377, function () {
//jQuery(_this).text(woof_lang_show_products_filter);
jQuery('.woof_auto_show').addClass('woof_overflow_hidden');
jQuery('.woof_auto_show_indent').addClass('woof_overflow_hidden');
woof_init_show_auto_form();
});
return false;
});
}
//if we have mode - child checkboxes closed - append openers buttons by js
function woof_checkboxes_slide() {
if (woof_checkboxes_slide_flag == true) {
var childs = jQuery('ul.woof_childs_list');
if (childs.size()) {
jQuery.each(childs, function (index, ul) {
var span_class = 'woof_is_closed';
if (jQuery(ul).find('input[type=checkbox],input[type=radio]').is(':checked')) {
jQuery(ul).show();
span_class = 'woof_is_opened';
}
jQuery(ul).before('<a href="javascript:void(0);" class="woof_childs_list_opener"><span class="' + span_class + '"></span></a>');
});
jQuery.each(jQuery('a.woof_childs_list_opener'), function (index, a) {
jQuery(a).click(function () {
var span = jQuery(this).find('span');
if (span.hasClass('woof_is_closed')) {
//lets open
jQuery(this).parent().find('ul.woof_childs_list').first().show(333);
span.removeClass('woof_is_closed');
span.addClass('woof_is_opened');
} else {
//lets close
jQuery(this).parent().find('ul.woof_childs_list').first().hide(333);
span.removeClass('woof_is_opened');
span.addClass('woof_is_closed');
}
return false;
});
});
}
}
}
function woof_init_ion_sliders() {
jQuery.each(jQuery('.woof_range_slider'), function (index, input) {
try {
jQuery(input).ionRangeSlider({
min: jQuery(input).data('min'),
max: jQuery(input).data('max'),
from: jQuery(input).data('min-now'),
to: jQuery(input).data('max-now'),
type: 'double',
prefix: jQuery(input).data('slider-prefix'),
postfix: jQuery(input).data('slider-postfix'),
prettify: true,
hideMinMax: false,
hideFromTo: false,
grid: true,
step: jQuery(input).data('step'),
onFinish: function (ui) {
woof_current_values.min_price = parseInt(ui.from, 10);
woof_current_values.max_price = parseInt(ui.to, 10);
//woocs adaptation
if (typeof woocs_current_currency !== 'undefined') {
woof_current_values.min_price = Math.ceil(woof_current_values.min_price / parseFloat(woocs_current_currency.rate));
woof_current_values.max_price = Math.ceil(woof_current_values.max_price / parseFloat(woocs_current_currency.rate));
}
//***
woof_ajax_page_num = 1;
//jQuery(input).within('.woof').length -> if slider is as shortcode
if (woof_autosubmit || jQuery(input).within('.woof').length == 0) {
woof_submit_link(woof_get_submit_link());
}
return false;
}
});
} catch (e) {
}
});
}
function woof_init_native_woo_price_filter() {
jQuery('.widget_price_filter form').unbind('submit');
jQuery('.widget_price_filter form').submit(function () {
var min_price = jQuery(this).find('.price_slider_amount #min_price').val();
var max_price = jQuery(this).find('.price_slider_amount #max_price').val();
woof_current_values.min_price = min_price;
woof_current_values.max_price = max_price;
woof_ajax_page_num = 1;
if (woof_autosubmit || jQuery(input).within('.woof').length == 0) {
//comment next code row to avoid endless ajax requests
woof_submit_link(woof_get_submit_link());
}
return false;
});
}
//we need after ajax redrawing of the search form
function woof_reinit_native_woo_price_filter() {
// woocommerce_price_slider_params is required to continue, ensure the object exists
if (typeof woocommerce_price_slider_params === 'undefined') {
return false;
}
// Get markup ready for slider
jQuery('input#min_price, input#max_price').hide();
jQuery('.price_slider, .price_label').show();
// Price slider uses jquery ui
var min_price = jQuery('.price_slider_amount #min_price').data('min'),
max_price = jQuery('.price_slider_amount #max_price').data('max'),
current_min_price = parseInt(min_price, 10),
current_max_price = parseInt(max_price, 10);
if (woof_current_values.hasOwnProperty('min_price')) {
current_min_price = parseInt(woof_current_values.min_price, 10);
current_max_price = parseInt(woof_current_values.max_price, 10);
} else {
if (woocommerce_price_slider_params.min_price) {
current_min_price = parseInt(woocommerce_price_slider_params.min_price, 10);
}
if (woocommerce_price_slider_params.max_price) {
current_max_price = parseInt(woocommerce_price_slider_params.max_price, 10);
}
}
//***
jQuery(document.body).bind('price_slider_create price_slider_slide', function (event, min, max) {
if (typeof woocs_current_currency !== 'undefined') {
var label_min = min;
var label_max = max;
if (woocs_current_currency.rate !== 1) {
label_min = Math.ceil(label_min * parseFloat(woocs_current_currency.rate));
label_max = Math.ceil(label_max * parseFloat(woocs_current_currency.rate));
}
//+++
label_min = number_format(label_min, 2, '.', ',');
label_max = number_format(label_max, 2, '.', ',');
if (jQuery.inArray(woocs_current_currency.name, woocs_array_no_cents) || woocs_current_currency.hide_cents == 1) {
label_min = label_min.replace('.00', '');
label_max = label_max.replace('.00', '');
}
//+++
if (woocs_current_currency.position === 'left') {
jQuery('.price_slider_amount span.from').html(woocommerce_price_slider_params.currency_symbol + label_min);
jQuery('.price_slider_amount span.to').html(woocommerce_price_slider_params.currency_symbol + label_max);
} else if (woocs_current_currency.position === 'left_space') {
jQuery('.price_slider_amount span.from').html(woocommerce_price_slider_params.currency_symbol + " " + label_min);
jQuery('.price_slider_amount span.to').html(woocommerce_price_slider_params.currency_symbol + " " + label_max);
} else if (woocs_current_currency.position === 'right') {
jQuery('.price_slider_amount span.from').html(label_min + woocommerce_price_slider_params.currency_symbol);
jQuery('.price_slider_amount span.to').html(label_max + woocommerce_price_slider_params.currency_symbol);
} else if (woocs_current_currency.position === 'right_space') {
jQuery('.price_slider_amount span.from').html(label_min + " " + woocommerce_price_slider_params.currency_symbol);
jQuery('.price_slider_amount span.to').html(label_max + " " + woocommerce_price_slider_params.currency_symbol);
}
} else {
if (woocommerce_price_slider_params.currency_pos === 'left') {
jQuery('.price_slider_amount span.from').html(woocommerce_price_slider_params.currency_symbol + min);
jQuery('.price_slider_amount span.to').html(woocommerce_price_slider_params.currency_symbol + max);
} else if (woocommerce_price_slider_params.currency_pos === 'left_space') {
jQuery('.price_slider_amount span.from').html(woocommerce_price_slider_params.currency_symbol + ' ' + min);
jQuery('.price_slider_amount span.to').html(woocommerce_price_slider_params.currency_symbol + ' ' + max);
} else if (woocommerce_price_slider_params.currency_pos === 'right') {
jQuery('.price_slider_amount span.from').html(min + woocommerce_price_slider_params.currency_symbol);
jQuery('.price_slider_amount span.to').html(max + woocommerce_price_slider_params.currency_symbol);
} else if (woocommerce_price_slider_params.currency_pos === 'right_space') {
jQuery('.price_slider_amount span.from').html(min + ' ' + woocommerce_price_slider_params.currency_symbol);
jQuery('.price_slider_amount span.to').html(max + ' ' + woocommerce_price_slider_params.currency_symbol);
}
}
jQuery(document.body).trigger('price_slider_updated', [min, max]);
});
jQuery('.price_slider').slider({
range: true,
animate: true,
min: min_price,
max: max_price,
values: [current_min_price, current_max_price],
create: function () {
jQuery('.price_slider_amount #min_price').val(current_min_price);
jQuery('.price_slider_amount #max_price').val(current_max_price);
jQuery(document.body).trigger('price_slider_create', [current_min_price, current_max_price]);
},
slide: function (event, ui) {
jQuery('input#min_price').val(ui.values[0]);
jQuery('input#max_price').val(ui.values[1]);
jQuery(document.body).trigger('price_slider_slide', [ui.values[0], ui.values[1]]);
},
change: function (event, ui) {
jQuery(document.body).trigger('price_slider_change', [ui.values[0], ui.values[1]]);
}
});
//***
woof_init_native_woo_price_filter();
}
function woof_init_toggles() {
jQuery('.woof_front_toggle').life('click', function () {
if (jQuery(this).data('condition') == 'opened') {
jQuery(this).removeClass('woof_front_toggle_opened');
jQuery(this).addClass('woof_front_toggle_closed');
jQuery(this).data('condition', 'closed');
if (woof_toggle_type == 'text') {
jQuery(this).text(woof_toggle_closed_text);
} else {
jQuery(this).find('img').prop('src', woof_toggle_closed_image);
}
} else {
jQuery(this).addClass('woof_front_toggle_opened');
jQuery(this).removeClass('woof_front_toggle_closed');
jQuery(this).data('condition', 'opened');
if (woof_toggle_type == 'text') {
jQuery(this).text(woof_toggle_opened_text);
} else {
jQuery(this).find('img').prop('src', woof_toggle_opened_image);
}
}
jQuery(this).parents('.woof_container_inner').find('.woof_block_html_items').toggle(500);
return false;
});
}
<?php if (!defined('ABSPATH')) die('No direct access allowed'); ?>
<?php
//+++
$args = array();
$args['show_count'] = get_option('woof_show_count', 0);
$args['show_count_dynamic'] = get_option('woof_show_count_dynamic', 0);
$args['hide_dynamic_empty_pos'] = get_option('woof_hide_dynamic_empty_pos', 0);
$args['woof_autosubmit'] = $autosubmit;
//***
$_REQUEST['tax_only'] = $tax_only;
$_REQUEST['tax_exclude'] = $tax_exclude;
$_REQUEST['by_only'] = $by_only;
if (!function_exists('woof_only'))
{
function woof_only($key_slug, $type = 'taxonomy')
{
switch ($type)
{
case 'taxonomy':
if (!empty($_REQUEST['tax_only']))
{
if (!in_array($key_slug, $_REQUEST['tax_only']))
{
return FALSE;
}
}
if (!empty($_REQUEST['tax_exclude']))
{
if (in_array($key_slug, $_REQUEST['tax_exclude']))
{
return FALSE;
}
}
break;
case 'item':
if (!empty($_REQUEST['by_only']))
{
if (!in_array($key_slug, $_REQUEST['by_only']))
{
return FALSE;
}
}
break;
}
return TRUE;
}
}
//***
if (!function_exists('woof_print_tax'))
{
function woof_print_tax($taxonomies, $tax_slug, $terms, $exclude_tax_key, $taxonomies_info, $additional_taxes, $woof_settings, $args, $counter)
{
global $WOOF;
if ($exclude_tax_key == $tax_slug)
{
//$terms = apply_filters('woof_exclude_tax_key', $terms);
if (empty($terms))
{
return;
}
}
//***
if (!woof_only($tax_slug, 'taxonomy'))
{
return;
}
//***
$args['taxonomy_info'] = $taxonomies_info[$tax_slug];
$args['tax_slug'] = $tax_slug;
$args['terms'] = $terms;
$args['all_terms_hierarchy'] = $taxonomies[$tax_slug];
$args['additional_taxes'] = $additional_taxes;
//***
$woof_container_styles = "";
if ($woof_settings['tax_type'][$tax_slug] == 'radio' OR $woof_settings['tax_type'][$tax_slug] == 'checkbox')
{
if ($WOOF->settings['tax_block_height'][$tax_slug] > 0)
{
$woof_container_styles = "max-height:{$WOOF->settings['tax_block_height'][$tax_slug]}px; overflow-y: auto;";
}
}
//***
//https://wordpress.org/support/topic/adding-classes-woof_container-div
$primax_class = sanitize_key(WOOF_HELPER::wpml_translate($taxonomies_info[$tax_slug]));
?>
<div data-css-class="woof_container_<?php echo $tax_slug ?>" class="woof_container woof_container_<?php echo $woof_settings['tax_type'][$tax_slug] ?> woof_container_<?php echo $tax_slug ?> woof_container_<?php echo $counter ?> woof_container_<?php echo $primax_class ?>">
<div class="woof_container_overlay_item"></div>
<div class="woof_container_inner woof_container_inner_<?php echo $primax_class ?>">
<?php
$css_classes = "woof_block_html_items";
$show_toggle = (int) $WOOF->settings['show_toggle_button'][$tax_slug];
//***
$search_query = $WOOF->get_request_data();
$block_is_closed = true;
if (in_array($tax_slug, array_keys($search_query)))
{
$block_is_closed = false;
}
if ($show_toggle === 1 AND ! in_array($tax_slug, array_keys($search_query)))
{
$css_classes.=" woof_closed_block";
}
if ($show_toggle === 2 AND ! in_array($tax_slug, array_keys($search_query)))
{
$block_is_closed = false;
}
//***
switch ($woof_settings['tax_type'][$tax_slug])
{
case 'checkbox':
if ($WOOF->settings['show_title_label'][$tax_slug])
{
?>
<<?php echo apply_filters('woof_title_tag', 'h4'); ?>><?php echo WOOF_HELPER::wpml_translate($taxonomies_info[$tax_slug]) ?><?php WOOF_HELPER::draw_title_toggle($show_toggle, $block_is_closed); ?></<?php echo apply_filters('woof_title_tag', 'h4'); ?>>
<?php
}
if (!empty($woof_container_styles))
{
$css_classes.=" woof_section_scrolled";
}
?>
<div class="<?php echo $css_classes ?>" <?php if (!empty($woof_container_styles)): ?>style="<?php echo $woof_container_styles ?>"<?php endif; ?>>
<?php
echo $WOOF->render_html(WOOF_PATH . 'views/html_types/checkbox.php', $args);
?>
</div>
<?php
break;
case 'select':
if ($WOOF->settings['show_title_label'][$tax_slug])
{
?>
<<?php echo apply_filters('woof_title_tag', 'h4'); ?>><?php echo WOOF_HELPER::wpml_translate($taxonomies_info[$tax_slug]) ?><?php WOOF_HELPER::draw_title_toggle($show_toggle, $block_is_closed); ?></<?php echo apply_filters('woof_title_tag', 'h4'); ?>>
<?php
}
?>
<div class="<?php echo $css_classes ?>">
<?php
echo $WOOF->render_html(WOOF_PATH . 'views/html_types/select.php', $args);
?>
</div>
<?php
break;
case 'mselect':
if ($WOOF->settings['show_title_label'][$tax_slug])
{
?>
<<?php echo apply_filters('woof_title_tag', 'h4'); ?>><?php echo WOOF_HELPER::wpml_translate($taxonomies_info[$tax_slug]) ?><?php WOOF_HELPER::draw_title_toggle($show_toggle, $block_is_closed); ?></<?php echo apply_filters('woof_title_tag', 'h4'); ?>>
<?php
}
?>
<div class="<?php echo $css_classes ?>">
<?php
echo $WOOF->render_html(WOOF_PATH . 'views/html_types/mselect.php', $args);
?>
</div>
<?php
break;
default:
if ($WOOF->settings['show_title_label'][$tax_slug])
{
?>
<<?php echo apply_filters('woof_title_tag', 'h4'); ?>><?php echo WOOF_HELPER::wpml_translate($taxonomies_info[$tax_slug]) ?><?php WOOF_HELPER::draw_title_toggle($show_toggle, $block_is_closed); ?></<?php echo apply_filters('woof_title_tag', 'h4'); ?>>
<?php
}
if (!empty($woof_container_styles))
{
$css_classes.=" woof_section_scrolled";
}
?>
<div class="<?php echo $css_classes ?>" <?php if (!empty($woof_container_styles)): ?>style="<?php echo $woof_container_styles ?>"<?php endif; ?>>
<?php
if (!empty(WOOF_EXT::$includes['taxonomy_type_objects']))
{
$is_custom = false;
foreach (WOOF_EXT::$includes['taxonomy_type_objects'] as $obj)
{
if ($obj->html_type == $woof_settings['tax_type'][$tax_slug])
{
$is_custom = true;
$args['woof_settings'] = $woof_settings;
$args['taxonomies_info'] = $taxonomies_info;
echo $WOOF->render_html($obj->get_html_type_view(), $args);
break;
}
}
if (!$is_custom)
{
echo $WOOF->render_html(WOOF_PATH . 'views/html_types/radio.php', $args);
}
} else
{
echo $WOOF->render_html(WOOF_PATH . 'views/html_types/radio.php', $args);
}
?>
</div>
<?php
break;
}
?>
<input type="hidden" name="woof_t_<?php echo $tax_slug ?>" value="<?php echo $taxonomies_info[$tax_slug]->labels->name ?>" /><!-- for red button search nav panel -->
</div>
</div>
<?php
}
}
if (!function_exists('woof_print_item_by_key'))
{
function woof_print_item_by_key($key, $woof_settings, $additional_taxes)
{
if (!woof_only($key, 'item'))
{
return;
}
//***
global $WOOF;
switch ($key)
{
case 'by_price':
$price_filter = 0;
if (isset($WOOF->settings['by_price']['show']))
{
$price_filter = (int) $WOOF->settings['by_price']['show'];
}
?>
<?php if ($price_filter == 1): ?>
<div data-css-class="woof_price_search_container" class="woof_price_search_container woof_container">
<div class="woof_container_overlay_item"></div>
<div class="woof_container_inner">
<div class="woocommerce widget_price_filter">
<?php //the_widget('WC_Widget_Price_Filter', array('title' => '')); ?>
<?php if (isset($WOOF->settings['by_price']['title_text']) AND ! empty($WOOF->settings['by_price']['title_text'])): ?>
<<?php echo apply_filters('woof_title_tag', 'h4'); ?>><?php echo $WOOF->settings['by_price']['title_text']; ?></<?php echo apply_filters('woof_title_tag', 'h4'); ?>>
<?php endif; ?>
<?php WOOF_HELPER::price_filter(); ?>
</div>
</div>
</div>
<div style="clear:both;"></div>
<?php endif; ?>
<?php if ($price_filter == 2): ?>
<div data-css-class="woof_price2_search_container" class="woof_price2_search_container woof_container">
<div class="woof_container_overlay_item"></div>
<div class="woof_container_inner">
<?php if (isset($WOOF->settings['by_price']['title_text']) AND ! empty($WOOF->settings['by_price']['title_text'])): ?>
<<?php echo apply_filters('woof_title_tag', 'h4'); ?>><?php echo $WOOF->settings['by_price']['title_text']; ?></<?php echo apply_filters('woof_title_tag', 'h4'); ?>>
<?php endif; ?>
<?php echo do_shortcode('[woof_price_filter type="select" additional_taxes="' . $additional_taxes . '"]'); ?>
</div>
</div>
<?php endif; ?>
<?php if ($price_filter == 3): ?>
<div data-css-class="woof_price3_search_container" class="woof_price3_search_container woof_container">
<div class="woof_container_overlay_item"></div>
<div class="woof_container_inner">
<?php if (isset($WOOF->settings['by_price']['title_text']) AND ! empty($WOOF->settings['by_price']['title_text'])): ?>
<<?php echo apply_filters('woof_title_tag', 'h4'); ?>><?php echo $WOOF->settings['by_price']['title_text']; ?></<?php echo apply_filters('woof_title_tag', 'h4'); ?>>
<?php endif; ?>
<?php echo do_shortcode('[woof_price_filter type="slider" additional_taxes="' . $additional_taxes . '"]'); ?>
</div>
</div>
<?php endif; ?>
<?php
break;
default:
do_action('woof_print_html_type_' . $key);
break;
}
}
}
?>
<?php if ($autohide): ?>
<div>
<?php
if (isset($this->settings['woof_auto_hide_button_img']) AND ! empty($this->settings['woof_auto_hide_button_img']))
{
if ($this->settings['woof_auto_hide_button_img'] != 'none')
{
?>
<style type="text/css">
.woof_show_auto_form,.woof_hide_auto_form
{
background-image: url('<?php echo $this->settings['woof_auto_hide_button_img'] ?>') !important;
}
</style>
<?php
} else
{
?>
<style type="text/css">
.woof_show_auto_form,.woof_hide_auto_form
{
background-image: none !important;
}
</style>
<?php
}
}
//***
$woof_auto_hide_button_txt = '';
if (isset($this->settings['woof_auto_hide_button_txt']))
{
$woof_auto_hide_button_txt = $this->settings['woof_auto_hide_button_txt'];
}
?>
<a href="javascript:void(0);" class="woof_show_auto_form <?php if (isset($this->settings['woof_auto_hide_button_img']) AND $this->settings['woof_auto_hide_button_img'] == 'none') echo 'woof_show_auto_form_txt'; ?>"><?php echo $woof_auto_hide_button_txt ?></a><br />
<div class="woof_auto_show woof_overflow_hidden" style="opacity: 0; height: 1px;">
<div class="woof_auto_show_indent woof_overflow_hidden">
<?php endif; ?>
<div class="woof <?php if (!empty($sid)): ?>woof_sid woof_sid_<?php echo $sid ?><?php endif; ?>" <?php if (!empty($sid)): ?>data-sid="<?php echo $sid; ?>"<?php endif; ?> data-shortcode="<?php echo(isset($_REQUEST['woof_shortcode_txt']) ? $_REQUEST['woof_shortcode_txt'] : 'woof') ?>" data-redirect="<?php echo $redirect ?>" data-autosubmit="<?php echo $autosubmit ?>" data-ajax-redraw="<?php echo $ajax_redraw ?>">
<?php if ($show_woof_edit_view AND ! empty($sid)): ?>
<a href="#" class="woof_edit_view" data-sid="<?php echo $sid ?>"><?php _e('show blocks helper', 'woocommerce-products-filter') ?></a>
<div></div>
<?php endif; ?>
<!--- here is possible drop html code which is never redraws by AJAX ---->
<div class="woof_redraw_zone">
<?php
global $wp_query;
//+++
//if (!empty($taxonomies))
{
$exclude_tax_key = '';
//code-bone for pages like
//http://dev.pluginus.net/product-category/clothing/ with GET params
//another way when GET is actual no possibility get current taxonomy
if ($this->is_really_current_term_exists())
{
$o = $this->get_really_current_term();
$exclude_tax_key = $o->taxonomy;
//do_shortcode("[woof_products_ids_prediction taxonomies=product_cat:{$o->term_id}]");
//echo $o->term_id;exit;
}
//***
if (!empty($wp_query->query))
{
if (isset($wp_query->query_vars['taxonomy']) AND in_array($wp_query->query_vars['taxonomy'], get_object_taxonomies('product')))
{
$taxes = $wp_query->query;
if (isset($taxes['paged']))
{
unset($taxes['paged']);
}
foreach ($taxes as $key => $value)
{
if (in_array($key, array_keys($this->get_request_data())))
{
unset($taxes[$key]);
}
}
//***
if (!empty($taxes))
{
$t = array_keys($taxes);
$v = array_values($taxes);
//***
$exclude_tax_key = $t[0];
$_REQUEST['WOOF_IS_TAX_PAGE'] = $exclude_tax_key;
}
}
} else
{
//***
}
//***
$items_order = array();
$taxonomies_keys = array_keys($taxonomies);
if (isset($woof_settings['items_order']) AND ! empty($woof_settings['items_order']))
{
$items_order = explode(',', $woof_settings['items_order']);
} else
{
$items_order = array_merge($this->items_keys, $taxonomies_keys);
}
//*** lets check if we have new taxonomies added in woocommerce or new item
foreach (array_merge($this->items_keys, $taxonomies_keys) as $key)
{
if (!in_array($key, $items_order))
{
$items_order[] = $key;
}
}
//lets print our items and taxonomies
$counter = 0;
foreach ($items_order as $key)
{
if (in_array($key, $this->items_keys))
{
woof_print_item_by_key($key, $woof_settings, $additional_taxes);
} else
{
if (!isset($woof_settings['tax'][$key]))
{
continue;
}
woof_print_tax($taxonomies, $key, $taxonomies[$key], $exclude_tax_key, $taxonomies_info, $additional_taxes, $woof_settings, $args, $counter);
}
$counter++;
}
}
?>
<div class="woof_submit_search_form_container">
<?php if ($this->is_isset_in_request_data($this->get_swoof_search_slug())): global $woof_link; ?>
<?php
$woof_reset_btn_txt = get_option('woof_reset_btn_txt', '');
if (empty($woof_reset_btn_txt))
{
$woof_reset_btn_txt = __('Reset', 'woocommerce-products-filter');
}
?>
<?php if ($woof_reset_btn_txt != 'none'): ?>
<button style="float: right;" class="button woof_reset_search_form" data-link="http://your_link"><?php echo $woof_reset_btn_txt ?></button>
<?php endif; ?>
<?php endif; ?>
<?php if (!$autosubmit OR $ajax_redraw): ?>
<?php
$woof_filter_btn_txt = get_option('woof_filter_btn_txt', '');
if (empty($woof_filter_btn_txt))
{
$woof_filter_btn_txt = __('Filter', 'woocommerce-products-filter');
}
?>
<button style="float: left;" class="button woof_submit_search_form"><?php echo $woof_filter_btn_txt ?></button>
<?php endif; ?>
</div>
</div>
</div>
<?php if ($autohide): ?>
</div>
</div>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment