File: /var/www/shoetique/wp-content/plugins/prdctfltr25/prdctfltr.php
<?php
/*
Plugin Name: WooCommerce Product Filter
Plugin URI: http://www.mihajlovicnenad.com/product-filter
Description: Advanced product filter for any Wordpress template! - mihajlovicnenad.com
Author: Mihajlovic Nenad
Version: 3.2.0
Author URI: http://www.mihajlovicnenad.com
*/
/**
* Product Filter Translation
*/
function prdctfltr_plugin_setup() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'prdctfltr' );
$dir = trailingslashit( WP_LANG_DIR );
load_plugin_textdomain( 'prdctfltr', false, $dir . 'plugins' );
}
add_action('init', 'prdctfltr_plugin_setup');
/**
* Product Filter Basic
*/
$curr_path = dirname( __FILE__ );
$curr_name = basename( $curr_path );
$curr_url = plugins_url( "/$curr_name/" );
define( 'PRDCTFLTR_URL', $curr_url );
function prdctfltr_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/*
* Product Filter Load Scripts
*/
if ( !function_exists('prdctfltr_scripts') ) :
function prdctfltr_scripts() {
$curr_scripts = get_option( 'wc_settings_prdctfltr_disable_scripts', array() );
$curr_js = get_option( 'wc_settings_prdctfltr_ajax_js', '' );
wp_register_style( 'prdctfltr-main-css', PRDCTFLTR_URL .'lib/css/prdctfltr.css', false, '3.2.0' );
wp_enqueue_style( 'prdctfltr-main-css' );
if ( !in_array( 'mcustomscroll', $curr_scripts ) ) {
wp_register_style( 'prdctfltr-scrollbar-css', PRDCTFLTR_URL .'lib/css/jquery.mCustomScrollbar.css', false, '3.2.0' );
wp_enqueue_style( 'prdctfltr-scrollbar-css' );
wp_register_script( 'prdctfltr-scrollbar-js', PRDCTFLTR_URL .'lib/js/jquery.mCustomScrollbar.concat.min.js', array( 'jquery' ), '3.2.0', true );
wp_enqueue_script( 'prdctfltr-scrollbar-js' );
}
if ( !in_array( 'isotope', $curr_scripts ) ) {
wp_register_script( 'prdctfltr-isotope-js', PRDCTFLTR_URL .'lib/js/isotope.js', array( 'jquery' ), '3.2.0', true );
wp_enqueue_script( 'prdctfltr-isotope-js' );
}
if ( !in_array( 'ionrange', $curr_scripts ) ) {
wp_register_style( 'prdctfltr-ionrange-css', PRDCTFLTR_URL .'lib/css/ion.rangeSlider.css', false, '3.2.0' );
wp_enqueue_style( 'prdctfltr-ionrange-css' );
wp_register_script( 'prdctfltr-ionrange-js', PRDCTFLTR_URL .'lib/js/ion.rangeSlider.min.js', array( 'jquery' ), '3.2.0', false );
wp_enqueue_script( 'prdctfltr-ionrange-js' );
}
wp_register_script( 'prdctfltr-main-js', PRDCTFLTR_URL .'lib/js/prdctfltr_main.js', array( 'jquery' ), '3.2.0', true );
wp_enqueue_script( 'prdctfltr-main-js' );
$curr_args = array(
'ajax' => admin_url( 'admin-ajax.php' ),
'js' => $curr_js
);
wp_localize_script( 'prdctfltr-main-js', 'prdctfltr', $curr_args );
}
endif;
add_action( 'wp_enqueue_scripts', 'prdctfltr_scripts' );
/*
* Product Filter Admin Scripts
*/
function prdctfltr_admin_scripts($hook) {
if ( isset( $_GET['page'], $_GET['tab'] ) && ($_GET['page'] == 'wc-settings' || $_GET['page'] == 'woocommerce_settings' ) && $_GET['tab'] == 'settings_products_filter' ) {
wp_register_style( 'prdctfltr-admin', PRDCTFLTR_URL .'lib/css/admin.css', false, '3.2.0' );
wp_enqueue_style( 'prdctfltr-admin' );
wp_register_script( 'prdctfltr-settings', PRDCTFLTR_URL . 'lib/js/admin.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable' ), '3.2.0', true );
wp_enqueue_script( 'prdctfltr-settings' );
$curr_args = array(
'ajax' => admin_url( 'admin-ajax.php' )
);
wp_localize_script( 'prdctfltr-settings', 'prdctfltr', $curr_args );
}
}
add_action( 'admin_enqueue_scripts', 'prdctfltr_admin_scripts' );
/*
* Product Filter Pre_Get_Posts
*/
if ( !function_exists( 'prdctfltr_wc_meta_query' ) ) :
function prdctfltr_wc_meta_query($query) {
if ( ( !is_admin() && isset( $query->query['prdctfltr'] ) && $query->query['prdctfltr'] == 'active' ) !== false ) {
$pf_mode = 'shortcode';
}
else if ( !is_admin() && $query->is_main_query() && ( $query->is_tax( get_object_taxonomies( 'product' ) ) || $query->is_post_type_archive( 'product' ) || $query->query_vars['page_id'] == ( prdctfltr_wpml_get_id( wc_get_page_id( 'shop' ) ) ) ) ) {
$pf_mode = 'archive';
}
else {
if ( ( defined('DOING_AJAX') && DOING_AJAX ) === false ) {
return;
}
$pf_mode = 'shortcode';
}
$curr_args = array();
$pf_next = array();
$f_attrs = array();
$f_terms = array();
$rng_terms = array();
$product_taxonomies = get_object_taxonomies( 'product' );
$pf_not_allowed = array( 'product_cat', 'product_tag', 'characteristics', 'product_type' );
foreach ( $product_taxonomies as $pf_tax ) {
if ( !in_array( $pf_tax, $pf_not_allowed ) ) {
$pf_next[] = $pf_tax;
}
}
$pf_not_allowed = array( 'widget_search' );
if ( ( defined('DOING_AJAX') && DOING_AJAX ) && isset( $query->query ) ) {
foreach( $query->query as $k => $v ){
if ( !in_array($k, $pf_not_allowed) ) {
if ( substr($k, 0, 4) == 'rng_' && $v !== '' ) {
if ( substr($k, 0, 8) == 'rng_min_' ) {
$rng_terms[str_replace('rng_min_', '', $k)]['min'] = $v;
}
else if ( substr($k, 0, 8) == 'rng_max_' ) {
$rng_terms[str_replace('rng_max_', '', $k)]['max'] = $v;
}
else if ( substr($k, 0, 10) == 'rng_order_' ) {
$rng_terms[str_replace('rng_order_', '', $k)]['order'] = $v;
}
$_GET[$k] = $v;
}
else if ( in_array($k, $pf_next) && substr($k, 0, 3) == 'pa_' ) {
$_GET[$k] = $v;
}
else if ( in_array( $k, $product_taxonomies ) ) {
$_GET[$k] = $v;
}
}
}
}
$pf_not_allowed = array( 'product_cat', 'product_tag', 'characteristics', 'min_price', 'max_price', 'orderby', 'sale_products', 'instock_products', 'widget_search', 'page_id', 'lang' );
foreach( $_GET as $k => $v ){
if ( !in_array($k, $pf_not_allowed) ) {
if ( substr($k, 0, 4) == 'rng_' && $v !== '' ) {
$curr_val = str_replace('rng_max_', '', $k);
if ( substr($k, 0, 8) == 'rng_min_' ) {
$rng_terms[str_replace('rng_min_', '', $k)]['min'] = $v;
}
else if ( substr($k, 0, 8) == 'rng_max_' ) {
$rng_terms[str_replace('rng_max_', '', $k)]['max'] = $v;
}
else if ( substr($k, 0, 12) == 'rng_orderby_' ) {
$rng_terms[str_replace('rng_orderby_', '', $k)]['orderby'] = $v;
}
else if ( substr($k, 0, 10) == 'rng_order_' ) {
$rng_terms[str_replace('rng_order_', '', $k)]['order'] = $v;
}
}
else if ( in_array($k, $pf_next) && substr($k, 0, 3) == 'pa_' ) {
$curr_args = array_merge( $curr_args, array(
$k => $v
) );
$f_attrs[] = '"attribute_'.$k.'"';
if ( strpos($v, ',') ) {
$v_val = explode(',', $v);
foreach ( $v_val as $o => $z ) {
$f_terms[] = '"'.$z.'"';
}
}
else if ( strpos($v, '+') ) {
$v_val = explode('+', $v);
foreach ( $v_val as $o => $z ) {
$f_terms[] = '"'.$z.'"';
}
}
else {
$f_terms[] = '"'.$v.'"';
}
}
else if ( in_array( $k, $product_taxonomies ) ) {
$curr_args = array_merge( $curr_args, array(
$k => $v
) );
}
}
}
if ( !empty($rng_terms) ) {
foreach ( $rng_terms as $rng_name => $rng_inside ) {
if ( ( isset($rng_inside['min']) && isset($rng_inside['max']) ) === false ) {
continue;
}
if ( !in_array( $rng_name, array( 'price' ) ) ) {
if ( isset($rng_terms[$rng_name]['orderby']) && $rng_terms[$rng_name]['orderby'] == 'number' ) {
$attr_args = array(
'hide_empty' => 1,
'orderby' => 'slug'
);
$sort_args = array(
'order' => ( isset( $rng_terms[$rng_name]['order'] ) ? $rng_terms[$rng_name]['order'] : 'ASC' )
);
$curr_attributes = get_terms( $rng_name, $attr_args );
$curr_attributes = prdctfltr_sort_terms_naturally( $curr_attributes, $sort_args );
}
else if ( isset($rng_terms[$rng_name]['orderby']) && $rng_terms[$rng_name]['orderby'] !== '' ) {
$attr_args = array(
'hide_empty' => 1,
'orderby' => $rng_terms[$rng_name]['orderby'],
'order' => ( isset( $rng_terms[$rng_name]['order'] ) ? $rng_terms[$rng_name]['order'] : 'ASC' )
);
$curr_attributes = get_terms( $rng_name, $attr_args );
}
else {
$attr_args = array(
'hide_empty' => 1
);
$curr_attributes = get_terms( $rng_name, $attr_args );
}
$rng_found = false;
$curr_ranges = array();
foreach ( $curr_attributes as $c => $s ) {
if ( $rng_found == true ) {
$curr_ranges[] = $s->slug;
if ( $s->slug == $rng_inside['max'] ) {
$rng_found = false;
continue;
}
}
if ( $s->slug == $rng_inside['min'] && $rng_found === false ) {
$rng_found = true;
$curr_ranges[] = $s->slug;
}
}
$curr_args = array_merge( $curr_args, array(
$rng_name => implode( $curr_ranges, ',' )
) );
$f_attrs[] = '"attribute_' . $rng_name . '"';
$f_terms_rng = array();
foreach ( $curr_ranges as $c ) {
$f_terms_rng[] = '"' . $c . '"';
}
$f_terms[] = implode( $f_terms_rng, ',' );
}
}
}
if ( !isset($_GET['orderby']) && isset($query->query['orderby']) && $query->query['orderby'] !== '' ) {
$_GET['orderby'] = $query->query['orderby'];
}
if ( isset($_GET['orderby']) ) {
if ( $_GET['orderby'] == 'price' || $_GET['orderby'] == 'price-desc' ) {
$orderby = 'meta_value_num';
$order = ( $_GET['orderby'] == 'price-desc' ? 'DESC' : 'ASC' );
$curr_args = array_merge( $curr_args, array(
'meta_key' => '_price',
'orderby' => $orderby,
'order' => $order
) );
}
else if ( $_GET['orderby'] == 'rating' ) {
add_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
}
else if ( $_GET['orderby'] == 'popularity' ) {
$orderby = 'meta_value_num';
$order = 'DESC';
$curr_args = array_merge( $curr_args, array(
'meta_key' => 'total_sales',
'orderby' => $orderby,
'order' => $order
) );
}
else {
$orderby = $_GET['orderby'];
$order = ( isset($_GET['order']) ? $_GET['order'] : 'DESC' );
$curr_args = array_merge( $curr_args, array(
'orderby' => $orderby,
'order' => $order
) );
}
}
if ( isset($_GET['product_cat']) && $_GET['product_cat'] !== '' ) {
$curr_args = array_merge( $curr_args, array(
'product_cat' => $_GET['product_cat']
) );
}
else if ( get_query_var('product_cat') !== '' ) {
$curr_args = array_merge( $curr_args, array(
'product_cat' => get_query_var('product_cat')
) );
}
else if ( isset($query->query['product_cat']) ) {
$curr_args = array_merge( $curr_args, array(
'product_cat' => $query->query['product_cat']
) );
}
if ( isset($_GET['product_tag']) && $_GET['product_tag'] !== '' ) {
$curr_args = array_merge( $curr_args, array(
'product_tag' => $_GET['product_tag']
) );
}
else if ( get_query_var('product_tag') !== '' ) {
$curr_args = array_merge( $curr_args, array(
'product_tag' => get_query_var('product_tag')
) );
}
else if ( isset($query->query['product_tag']) ) {
$curr_args = array_merge( $curr_args, array(
'product_tag' => $query->query['product_tag']
) );
}
if ( isset($_GET['characteristics']) && $_GET['characteristics'] !== '' ) {
$curr_args = array_merge( $curr_args, array(
'characteristics' => $_GET['characteristics']
) );
}
else if ( get_query_var('characteristics') !== '' ) {
$curr_args = array_merge( $curr_args, array(
'characteristics' => get_query_var('characteristics')
) );
}
else if ( isset($query->query['product_characteristics']) ) {
$curr_args = array_merge( $curr_args, array(
'characteristics' => $query->query['product_characteristics']
) );
}
if ( !isset($_GET['min_price']) && !isset($_GET['rng_min_price']) && isset($query->query['min_price']) && $query->query['min_price'] !== '' ) {
$_GET['min_price'] = $query->query['min_price'];
}
if ( !isset($_GET['max_price']) && !isset($_GET['rng_max_price']) && isset($query->query['max_price']) && $query->query['max_price'] !== '' ) {
$_GET['max_price'] = $query->query['max_price'];
}
if ( ( isset($_GET['min_price']) || isset($_GET['max_price']) ) !== false || ( isset($_GET['rng_min_price']) && isset($_GET['rng_max_price']) ) !== false || isset($_GET['sale_products']) ) {
add_filter( 'posts_join' , 'prdctfltr_join_price');
add_filter( 'posts_where' , 'prdctfltr_price_filter', 998, 2 );
}
if ( !isset($_GET['instock_products']) && isset($query->query['instock_products']) && $query->query['instock_products'] !== '' ) {
$_GET['instock_products'] = $query->query['instock_products'];
}
$curr_instock = get_option( 'wc_settings_prdctfltr_instock', 'no' );
if ( ( ( ( isset($_GET['instock_products']) && $_GET['instock_products'] !== '' && ( $_GET['instock_products'] == 'in' || $_GET['instock_products'] == 'out' ) ) || $curr_instock == 'yes' ) !== false ) && ( !isset($_GET['instock_products']) || $_GET['instock_products'] !== 'both' ) ) {
if ( !isset($_GET['instock_products']) && $curr_instock == 'yes' ) {
$i_arr['f_results'] = 'outofstock';
$i_arr['s_results'] = 'instock';
}
else if ( $_GET['instock_products'] == 'in' ) {
$i_arr['f_results'] = 'outofstock';
$i_arr['s_results'] = 'instock';
}
else if ( $_GET['instock_products'] == 'out' ) {
$i_arr['f_results'] = 'instock';
$i_arr['s_results'] = 'outofstock';
}
if ( count($f_terms) == 0 ) {
foreach($query->query as $k => $v){
if (substr($k, 0, 3) == 'pa_') {
$f_attrs[] = '"attribute_'.$k.'"';
if ( strpos($v, ',') ) {
$v_val = explode(',', $v);
foreach ( $v_val as $o => $z ) {
$f_terms[] = '"'.$z.'"';
}
}
else if ( strpos($v, '+') ) {
$v_val = explode('+', $v);
foreach ( $v_val as $o => $z ) {
$f_terms[] = '"'.$z.'"';
}
}
else {
$f_terms[] = '"'.$v.'"';
}
}
}
}
$curr_atts = join(',', $f_attrs);
$curr_terms = join(',', $f_terms);
$curr_count = count($f_attrs)+1;
if ( $curr_count > 1 ) {
global $wpdb;
$pf_exclude_product = $wpdb->get_results( $wpdb->prepare( '
SELECT DISTINCT(post_parent) FROM %1$s
INNER JOIN %2$s ON (%1$s.ID = %2$s.post_id)
WHERE %1$s.post_parent != "0"
AND %2$s.meta_key IN ("_stock_status",'.$curr_atts.')
AND %2$s.meta_value IN ("'.$i_arr['f_results'].'",'.$curr_terms.',"")
GROUP BY %2$s.post_id
HAVING COUNT(DISTINCT %2$s.meta_value) = ' . $curr_count .'
ORDER BY %1$s.ID ASC
', $wpdb->posts, $wpdb->postmeta ) );
$curr_in = array();
foreach ( $pf_exclude_product as $p ) {
$curr_in[] = $p->post_parent;
}
$pf_exclude_product_out = $wpdb->get_results( $wpdb->prepare( '
SELECT DISTINCT(post_parent) FROM %1$s
INNER JOIN %2$s ON (%1$s.ID = %2$s.post_id)
WHERE %1$s.post_parent != "0"
AND %2$s.meta_key IN ("_stock_status",'.$curr_atts.')
AND %2$s.meta_value IN ("'.$i_arr['s_results'].'",'.$curr_terms.',"")
GROUP BY %2$s.post_id
HAVING COUNT(DISTINCT %2$s.meta_value) = ' . $curr_count .'
ORDER BY %1$s.ID ASC
', $wpdb->posts, $wpdb->postmeta ) );
$curr_in_out = array();
foreach ( $pf_exclude_product_out as $p ) {
$curr_in_out[] = $p->post_parent;
}
if ( $curr_instock == 'yes' || $_GET['instock_products'] == 'in' ) {
foreach ( $curr_in as $q => $w ) {
if ( in_array( $w, $curr_in_out) ) {
unset($curr_in[$q]);
}
}
$curr_args = array_merge( $curr_args, array(
'post__not_in' => $curr_in
) );
add_filter( 'posts_join' , 'prdctfltr_join_instock');
add_filter( 'posts_where' , 'prdctfltr_instock_filter', 999, 2 );
}
else if ( $_GET['instock_products'] == 'out' ) {
foreach ( $curr_in_out as $e => $r ) {
if ( in_array( $r, $curr_in) ) {
unset($curr_in_out[$e]);
}
}
$pf_exclude_product_addon = $wpdb->get_results( $wpdb->prepare( '
SELECT DISTINCT(ID) FROM %1$s
INNER JOIN %2$s ON (%1$s.ID = %2$s.post_id)
WHERE %1$s.post_parent = "0"
AND %2$s.meta_key IN ("_stock_status",'.$curr_atts.')
AND %2$s.meta_value IN ("outofstock",'.$curr_terms.')
GROUP BY %2$s.post_id
ORDER BY %1$s.ID ASC
', $wpdb->posts, $wpdb->postmeta ) );
$curr_in_out_addon = array();
foreach ( $pf_exclude_product_addon as $a ) {
$curr_in_out_addon[] = $a->ID;
}
$curr_in_out = $curr_in_out + $curr_in_out_addon;
$curr_args = array_merge( $curr_args, array(
'post__in' => $curr_in_out
) );
}
}
else {
if ( !isset($_GET['instock_products']) && $curr_instock == 'yes' ) {
add_filter( 'posts_join' , 'prdctfltr_join_instock');
add_filter( 'posts_where' , 'prdctfltr_instock_filter', 999, 2 );
}
else if ( isset($_GET['instock_products']) && $_GET['instock_products'] == 'in' ) {
add_filter( 'posts_join' , 'prdctfltr_join_instock');
add_filter( 'posts_where' , 'prdctfltr_instock_filter', 999, 2 );
}
else if ( isset($_GET['instock_products']) && $_GET['instock_products'] == 'out' ) {
add_filter( 'posts_join' , 'prdctfltr_join_instock');
add_filter( 'posts_where' , 'prdctfltr_outofstock_filter', 999, 2 );
}
}
}
if ( isset($_GET['products_per_page']) && $_GET['products_per_page'] !== '' ) {
$curr_args = array_merge( $curr_args, array(
'posts_per_page' => floatval( $_GET['products_per_page'] )
) );
}
if ( isset($query->query['http_query']) ) {
parse_str(html_entity_decode($query->query['http_query']), $curr_http_args);
$curr_args = array_merge( $curr_http_args, $curr_args );
}
$pf_tax_query = array ();
foreach ( $curr_args as $k => $v ) {
if ( in_array($k, $product_taxonomies ) ) {
if ( strpos($v, ',') ) {
$pf_tax_query[] = array( 'taxonomy' => $k, 'field' => 'slug', 'terms' => explode(',', $v), 'operator' => 'IN' );
}
else if ( strpos($v, '+') ) {
if ( $k == 'product_cat' ) {
$operator = 'IN';
}
else {
$operator = 'AND';
}
$pf_tax_query[] = array( 'taxonomy' => $k, 'field' => 'slug', 'terms' => explode('+', $v), 'operator' => $operator );
}
else {
$pf_tax_query[] = array( 'taxonomy' => $k, 'field' => 'slug', 'terms' => array( $v ) );
}
$query->set( $k, $v );
}
else {
$query->set( $k, $v );
}
}
if ( !empty($pf_tax_query) ) {
$pf_tax_query['relation'] = 'AND';
$query->set( 'tax_query', $pf_tax_query );
}
}
endif;
add_filter('pre_get_posts','prdctfltr_wc_meta_query', 999999, 1);
/*
* Product Filter Sale Filter
*/
function prdctfltr_price_filter ( $where, &$wp_query ) {
global $wpdb;
if ( ( isset( $_GET['sale_products'] ) && $_GET['sale_products'] == 'on' ) !== false || ( isset( $wp_query->query_vars['sale_products'] ) && $wp_query->query_vars['sale_products'] ) !== false ) {
$pf_sale = true;
$pf_where_keys = array(
'"_sale_price","_min_variation_sale_price"',
'"_sale_price","_max_variation_sale_price"',
'meta_keys' => array( '_sale_price', '_min_variation_sale_price', '_max_variation_sale_price' )
);
}
else {
$pf_sale = false;
$pf_where_keys = array(
'"_price","_min_variation_price","_sale_price","_min_variation_sale_price"',
'"_price","_max_variation_price","_sale_price","_max_variation_sale_price"',
'meta_keys' => array( '_price', '_min_variation_price', '_max_variation_price' )
);
}
if ( isset( $wp_query->query_vars['rng_min_price'] ) ) {
$_min_price = $wp_query->query_vars['rng_min_price'];
}
if ( isset( $wp_query->query_vars['min_price'] ) ) {
$_min_price = $wp_query->query_vars['min_price'];
}
if ( isset( $_GET['rng_min_price'] ) ) {
$_min_price = $_GET['rng_min_price'];
}
if ( isset( $_GET['min_price'] ) ) {
$_min_price = $_GET['min_price'];
}
if ( !isset( $_min_price ) ) {
$_min = floor( $wpdb->get_var(
$wpdb->prepare('
SELECT min(meta_value + 0)
FROM %1$s
LEFT JOIN %2$s ON %1$s.ID = %2$s.post_id
WHERE ( meta_key = \'%3$s\' OR meta_key = \'%4$s\' )
AND meta_value != ""
', $wpdb->posts, $wpdb->postmeta, $pf_where_keys['meta_keys'][0], $pf_where_keys['meta_keys'][1] )
)
);
}
if ( isset( $wp_query->query_vars['rng_max_price'] ) ) {
$_max_price = $wp_query->query_vars['rng_max_price'];
}
if ( isset( $wp_query->query_vars['max_price'] ) ) {
$_max_price = $wp_query->query_vars['max_price'];
}
if ( isset( $_GET['rng_max_price'] ) ) {
$_max_price = $_GET['rng_max_price'];
}
if ( isset( $_GET['max_price'] ) ) {
$_max_price = $_GET['max_price'];
}
if ( !isset( $_max_price ) ) {
$_max = ceil( $wpdb->get_var(
$wpdb->prepare('
SELECT max(meta_value + 0)
FROM %1$s
LEFT JOIN %2$s ON %1$s.ID = %2$s.post_id
WHERE ( meta_key = \'%3$s\' OR meta_key = \'%4$s\' )
AND meta_value != ""
', $wpdb->posts, $wpdb->postmeta, $pf_where_keys['meta_keys'][0], $pf_where_keys['meta_keys'][2] )
) );
}
if ( ( isset($_min_price) || isset($_max_price) ) !== false ) {
if ( !isset( $_min_price) ) {
$_min_price = $_min;
}
if ( !isset( $_max_price) ) {
$_max_price = $_max;
}
$where .= " AND ( pf_price.meta_key IN ($pf_where_keys[0]) AND pf_price.meta_value >= $_min_price AND pf_price.meta_value != \"\" ) AND ( pf_price_max.meta_key IN ($pf_where_keys[1]) AND pf_price_max.meta_value <= $_max_price AND pf_price_max.meta_value != \"\" ) ";
}
else if ( $pf_sale === true ) {
$where .= " AND ( pf_price.meta_key IN (\"_sale_price\",\"_min_variation_sale_price\") AND pf_price.meta_value > 0 ) ";
}
remove_filter( 'posts_where' , 'prdctfltr_price_filter' );
return $where;
}
/*
* Product Filter Join Sale Tables
*/
function prdctfltr_join_price($join){
global $wpdb;
$join .= " JOIN $wpdb->postmeta AS pf_price ON $wpdb->posts.ID = pf_price.post_id JOIN $wpdb->postmeta AS pf_price_max ON $wpdb->posts.ID = pf_price_max.post_id ";
return $join;
}
/*
* Product Filter Instock Filter
*/
function prdctfltr_instock_filter ( $where, &$wp_query ) {
global $wpdb;
$where = str_replace("AND ( ($wpdb->postmeta.meta_key = '_visibility' AND CAST($wpdb->postmeta.meta_value AS CHAR) IN ('visible','catalog')) )", "", $where);
$where .= " AND ( pf_instock.meta_key LIKE '_stock_status' AND pf_instock.meta_value = 'instock' ) ";
remove_filter( 'posts_where' , 'prdctfltr_instock_filter' );
return $where;
}
/*
* Product Filter Outofstock Filter
*/
function prdctfltr_outofstock_filter ( $where, &$wp_query ) {
global $wpdb;
$where = str_replace("AND ( ($wpdb->postmeta.meta_key = '_visibility' AND CAST($wpdb->postmeta.meta_value AS CHAR) IN ('visible','catalog')) )", "", $where);
$where .= " AND ( pf_instock.meta_key LIKE '_stock_status' AND pf_instock.meta_value = 'outofstock' ) ";
remove_filter( 'posts_where' , 'prdctfltr_outofstock_filter' );
return $where;
}
/*
* Product Filter Join Instock Tables
*/
function prdctfltr_join_instock($join){
global $wpdb;
$join .= " JOIN $wpdb->postmeta AS pf_instock ON $wpdb->posts.ID = pf_instock.post_id ";
return $join;
}
/*
* Product Filter Register Characteristics
*/
$curr_char = get_option( 'wc_settings_prdctfltr_custom_tax', 'no' );
if ( $curr_char == 'yes' ) {
function prdctfltr_characteristics() {
$labels = array(
'name' => _x( 'Characteristics', 'taxonomy general name', 'prdctfltr' ),
'singular_name' => _x( 'Characteristics', 'taxonomy singular name', 'prdctfltr' ),
'search_items' => __( 'Search Characteristics', 'prdctfltr' ),
'popular_items' => __( 'Popular Characteristics', 'prdctfltr' ),
'all_items' => __( 'All Characteristics', 'prdctfltr' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Characteristics', 'prdctfltr' ),
'update_item' => __( 'Update Characteristics', 'prdctfltr' ),
'add_new_item' => __( 'Add New Characteristic', 'prdctfltr' ),
'new_item_name' => __( 'New Characteristic Name', 'prdctfltr' ),
'separate_items_with_commas' => __( 'Separate Characteristics with commas', 'prdctfltr' ),
'add_or_remove_items' => __( 'Add or remove characteristics', 'prdctfltr' ),
'choose_from_most_used' => __( 'Choose from the most used characteristics', 'prdctfltr' ),
'not_found' => __( 'No characteristics found.', 'prdctfltr' ),
'menu_name' => __( 'Characteristics', 'prdctfltr' ),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'characteristics' ),
);
register_taxonomy( 'characteristics', array('product'), $args );
}
add_action( 'init', 'prdctfltr_characteristics', 0 );
}
$curr_disable = get_option( 'wc_settings_prdctfltr_enable', 'yes' );
$curr_disable_def = get_option( 'wc_settings_prdctfltr_default_templates', 'yes' );
if ( $curr_disable == 'yes') {
/*
* Product Filter Override WooCommerce Template
*/
function prdctrfltr_add_filter ( $template, $slug, $name ) {
if ( $name ) {
$path = plugin_dir_path( __FILE__ ) . WC()->template_path() . "{$slug}-{$name}.php";
} else {
$path = plugin_dir_path( __FILE__ ) . WC()->template_path() . "{$slug}.php";
}
return file_exists( $path ) ? $path : $template;
}
add_filter( 'wc_get_template_part', 'prdctrfltr_add_filter', 10, 3 );
function prdctrfltr_add_loop_filter ( $template, $template_name, $template_path ) {
$path = plugin_dir_path( __FILE__ ) . $template_path . $template_name;
return file_exists( $path ) ? $path : $template;
}
add_filter( 'woocommerce_locate_template', 'prdctrfltr_add_loop_filter', 10, 3 );
}
if ( $curr_disable == 'no' && $curr_disable_def == 'yes' ) {
/*
* Product Filter Override WooCommerce Template
*/
function prdctrfltr_add_filter ( $template, $slug, $name ) {
if ( $name ) {
$path = plugin_dir_path( __FILE__ ) . 'blank/' . WC()->template_path() . "{$slug}-{$name}.php";
} else {
$path = plugin_dir_path( __FILE__ ) . 'blank/' . WC()->template_path() . "{$slug}.php";
}
return file_exists( $path ) ? $path : $template;
}
add_filter( 'wc_get_template_part', 'prdctrfltr_add_filter', 10, 3 );
function prdctrfltr_add_loop_filter ( $template, $template_name, $template_path ) {
$path = plugin_dir_path( __FILE__ ) . 'blank/' . $template_path . $template_name;
return file_exists( $path ) ? $path : $template;
}
add_filter( 'woocommerce_locate_template', 'prdctrfltr_add_loop_filter', 10, 3 );
}
/*
* Product Filter Search Variable Products
*/
function prdctrfltr_search_array($array, $attrs) {
$results = array();
$found = 0;
foreach ( $array as $subarray ) {
if ( isset( $subarray['attributes'] ) ) {
foreach ( $attrs as $k => $v ) {
if ( in_array($v, $subarray['attributes'] ) ) {
$found++;
}
}
}
if ( count($attrs) == $found ) {
$results[] = $subarray;
}
else if ( $found > 0 ) {
$results[] = $subarray;
}
$found = 0;
}
return $results;
}
/*
* Product Filter Get Variable Product
*/
$curr_variable = get_option( 'wc_settings_prdctfltr_use_variable_images', 'no' );
if ( $curr_variable == 'yes' ) {
if ( function_exists('runkit_function_rename') && function_exists( 'woocommerce_get_product_thumbnail' ) ) :
runkit_function_rename ( 'woocommerce_get_product_thumbnail', 'old_woocommerce_get_product_thumbnail' );
endif;
if ( !function_exists( 'woocommerce_get_product_thumbnail' ) ) :
function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0 ) {
$product = get_product( get_the_ID() );
if ( $product->is_type( 'variable' ) ) {
$attrs = array();
foreach( $_GET as $k => $v ){
if ( substr( $k, 0, 3 ) == 'pa_' ) {
if ( strpos($v, ',') ) {
$v_val = explode(',', $v);
$v_val = $v_val[0];
}
else if ( strpos($v, '+') ) {
$v_val = explode('+', $v);
$v_val = $v_val[0];
}
else {
$v_val = $v;
}
$attrs = $attrs + array(
$k => $v_val
);
}
}
if ( count( $attrs ) == 0 ) {
global $wp_the_query;
if ( isset( $wp_the_query->query ) ) {
foreach( $wp_the_query->query as $k => $v ){
if ( substr( $k, 0, 3 ) == 'pa_' ) {
if ( strpos($v, ',') ) {
$v_val = explode( ',', $v );
$v_val = $v_val[0];
}
else if ( strpos( $v, '+' ) ) {
$v_val = explode( '+', $v );
$v_val = $v_val[0];
}
else {
$v_val = $v;
}
$attrs = $attrs + array(
$k => $v_val
);
}
}
}
}
if ( count($attrs) == 0 ) {
global $prdctfltr_global;
if ( isset( $prdctfltr_global['active_filters'] ) ) {
foreach( $prdctfltr_global['active_filters'] as $k => $v ){
if ( substr( $k, 0, 3 ) == 'pa_' ) {
if ( strpos( $v, ',' ) ) {
$v_val = explode( ',', $v );
$v_val = $v_val[0];
}
else if ( strpos( $v, '+' ) ) {
$v_val = explode( '+', $v );
$v_val = $v_val[0];
}
else {
$v_val = $v;
}
$attrs = $attrs + array(
$k => $v_val
);
}
}
}
}
if ( is_product_taxonomy() ) {
$attrs = array_merge( $attrs, array( get_query_var('taxonomy') => get_query_var('term') ) );
}
if ( count($attrs) > 0 ) {
$curr_var = $product->get_available_variations();
foreach( $curr_var as $key => $var ) {
$curr_var_set[$key]['attributes'] = $var['attributes'];
$curr_var_set[$key]['variation_id'] = $var['variation_id'];
}
$found = prdctrfltr_search_array( $curr_var_set, $attrs );
}
}
if ( isset( $found[0] ) && $found[0]['variation_id'] && has_post_thumbnail( $found[0]['variation_id'] ) ) {
$image = get_the_post_thumbnail( $found[0]['variation_id'], $size );
} elseif ( has_post_thumbnail( $product->id ) ) {
$image = get_the_post_thumbnail( $product->id, $size );
} elseif ( ( $parent_id = wp_get_post_parent_id( $product->id ) ) && has_post_thumbnail( $parent_id ) ) {
$image = get_the_post_thumbnail( $product, $size );
} else {
$image = wc_placeholder_img( $size );
}
return $image;
}
endif;
}
/*
* Product Filter Sort Hierarchicaly
*/
function prdctfltr_sort_terms_hierarchicaly( Array &$cats, Array &$into, $parentId = 0 ) {
foreach ($cats as $i => $cat) {
if ($cat->parent == $parentId) {
$into[$cat->term_id] = $cat;
unset($cats[$i]);
}
}
foreach ($into as $topCat) {
$topCat->children = array();
prdctfltr_sort_terms_hierarchicaly($cats, $topCat->children, $topCat->term_id);
}
}
/*
* [prdctfltr_sc_products]
*/
function prdctfltr_sc_products( $atts, $content = null ) {
extract( shortcode_atts( array(
'preset' => '',
'rows' => 4,
'columns' => 4,
'ajax' => 'no',
'pagination' => 'yes',
'use_filter' => 'yes',
'no_products' => 'no',
'show_products' => 'yes',
'min_price' => '',
'max_price' => '',
'orderby' => '',
'order' => '',
'meta_key'=> '',
'product_cat'=> '',
'product_tag'=> '',
'product_characteristics'=> '',
'product_attributes'=> '',
'sale_products' => '',
'instock_products' => '',
'http_query' => '',
'disable_overrides' => 'yes',
'action' => '',
'bot_margin' => 36,
'class' => '',
'shortcode_id' => ''
), $atts ) );
global $paged;
$args = array();
if ( empty( $paged ) ) $paged = ( get_query_var('paged') ? get_query_var('paged') : 1 );
if ( $no_products == 'no' ) {
$args = $args + array (
'prdctfltr' => 'active'
);
}
else {
$use_filter = 'no';
$pagination = 'no';
$orderby = 'rand';
}
global $prdctfltr_global;
$prdctfltr_global['posts_per_page'] = $columns*$rows;
if ( $action !== '' ) {
$prdctfltr_global['action'] = $action;
}
if ( $preset !== '' ) {
$prdctfltr_global['preset'] = $preset;
}
if ( $disable_overrides !== '' ) {
$prdctfltr_global['disable_overrides'] = $disable_overrides;
}
$args = $args + array (
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => $prdctfltr_global['posts_per_page'],
'paged' => $paged,
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
);
if ( $orderby !== '' ) {
$args['orderby'] = $orderby;
}
if ( $order !== '' ) {
$args['order'] = $order;
}
if ( $order !== '' ) {
$args['meta_key'] = $meta_key;
}
if ( $min_price !== '' ) {
$args['min_price'] = $min_price;
}
if ( $max_price !== '' ) {
$args['max_price'] = $max_price;
}
if ( $product_cat !== '' ) {
$args['product_cat'] = $product_cat;
}
if ( $product_tag !== '' ) {
$args['product_tag'] = $product_tag;
}
if ( $product_characteristics !== '' ) {
$args['product_characteristics'] = $product_characteristics;
}
if ( $product_attributes !== '' ) {
$args['product_attributes'] = $product_attributes;
}
if ( $instock_products !== '' ) {
$args['instock_products'] = $instock_products;
}
if ( $sale_products !== '' ) {
$args['sale_products'] = $sale_products;
}
if ( $http_query !== '' ) {
$args['http_query'] = $http_query;
}
if ( $ajax == 'yes' ) {
$ajax_params = array(
( $preset !== '' ? $preset : 'false' ),
( $columns !== '' ? $columns : 'false' ),
( $rows !== '' ? $rows : 'false' ),
( $pagination !== '' ? $pagination : 'false' ),
( $no_products !== '' ? $no_products : 'false' ),
( $show_products !== '' ? $show_products : 'false' ),
( $use_filter !== '' ? $use_filter : 'false' ),
( $action !== '' ? $action : 'false' ),
( $bot_margin !== '' ? $bot_margin : 'false' ),
( $class !== '' ? $class : 'false' ),
( $shortcode_id !== '' ? $shortcode_id : 'false' ),
( $disable_overrides !== '' ? $disable_overrides : 'false' )
);
$pf_params = implode( '|', $ajax_params );
$add_ajax = ' data-query="' . http_build_query( $args ) . '" data-page="' . $paged . '" data-shortcode="' . $pf_params . '"';
}
$prdctfltr_global['sc_query'] = $args;
$bot_margin = (int)$bot_margin;
$margin = " style='margin-bottom:".$bot_margin."px'";
$out = '';
global $woocommerce, $woocommerce_loop;
$woocommerce_loop['columns'] = $columns;
$products = new WP_Query( $args );
ob_start();
if ( $products->have_posts() ) : ?>
<?php
if ( $use_filter == 'yes' ) {
include_once( plugin_dir_path( __FILE__ ) . 'woocommerce/loop/orderby.php' );
}
?>
<?php if ( $show_products == 'yes' ) { ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; ?>
<?php woocommerce_product_loop_end(); ?>
<?php
}
else {
$pagination = 'no';
}
?>
<?php
else :
wc_get_template( 'loop/no-products-found.php' );
endif;
$shortcode = ob_get_clean();
$out .= '<div' . ( $shortcode_id != '' ? ' id="'.$shortcode_id.'"' : '' ) . ' class="prdctfltr_sc_products woocommerce'.($ajax=='yes'? ' prdctfltr_ajax' : '' ).'' . ( $class != '' ? ' '.$class.'' : '' ) . '"'.$margin.($ajax=='yes' ? $add_ajax : '' ).'>';
$out .= do_shortcode($shortcode);
if ( $pagination == 'yes' ) {
ob_start();
?>
<nav class="woocommerce-pagination">
<?php
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
'base' => @add_query_arg('paged','%#%'),
'format' => '',
'current' => $paged,
'total' => $products->max_num_pages,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3
) ) );
?>
</nav>
<?php
$pagination = ob_get_clean();
$out .= $pagination;
}
$out .= '</div>';
wp_reset_postdata();
wp_reset_query();
return $out;
}
add_shortcode( 'prdctfltr_sc_products', 'prdctfltr_sc_products' );
/**
* Shortcode AJAX Respond
*/
function prdctfltr_respond() {
global $prdctfltr_global;
$shortcode_params = explode('|', $_POST['pf_shortcode']);
$preset = ( $shortcode_params[0] !== 'false' ? $shortcode_params[0] : '' );
$columns = ( $shortcode_params[1] !== 'false' ? $shortcode_params[1] : 4 );
$rows = ( $shortcode_params[2] !== 'false' ? $shortcode_params[2] : 4 );
$pagination = ( $shortcode_params[3] !== 'false' ? $shortcode_params[3] : '' );
$no_products = ( $shortcode_params[4] !== 'false' ? $shortcode_params[4] : '' );
$show_products = ( $shortcode_params[5] !== 'false' ? $shortcode_params[5] : '' );
$use_filter = ( $shortcode_params[6] !== 'false' ? $shortcode_params[6] : '' );
$action = ( $shortcode_params[7] !== 'false' ? $shortcode_params[7] : '' );
$bot_margin = ( $shortcode_params[8] !== 'false' ? $shortcode_params[8] : '' );
$class = ( $shortcode_params[9] !== 'false' ? $shortcode_params[9] : '' );
$shortcode_id = ( $shortcode_params[10] !== 'false' ? $shortcode_params[10] : '' );
$disable_overrides = ( $shortcode_params[11] !== 'false' ? $shortcode_params[11] : '' );
$res_paged = ( isset( $_POST['pf_paged'] ) ? $_POST['pf_paged'] : $_POST['pf_page'] );
$ajax_query = $_POST['pf_query'];
$current_page = prdctfltr_get_between( $ajax_query, 'paged=', '&' );
$page = $res_paged;
$args = str_replace( 'paged=' . $current_page . '&', 'paged=' . $page . '&', $ajax_query );
if ( $no_products == 'yes' ) {
$use_filter = 'no';
$pagination = 'no';
$orderby = 'rand';
}
$add_ajax = ' data-query="' . $args . '" data-page="' . $res_paged . '" data-shortcode="' . $_POST['pf_shortcode'] . '"';
$bot_margin = (int)$bot_margin;
$margin = " style='margin-bottom:" . $bot_margin . "px'";
if ( isset($_POST['pf_filters']) ) {
$curr_filters = $_POST['pf_filters'];
}
else {
$curr_filters = array();
}
$filter_args = '';
foreach ( $curr_filters as $k => $v ) {
if ( strpos($v, ',') ) {
$new_v = str_replace(',', '%2C', $v);
}
else if ( strpos($v, '+') ) {
$new_v = str_replace('+', '%2B', $v);
}
else {
$new_v = $v;
}
$filter_args .= '&' . $k . '=' . $new_v;
}
$args = $args . $filter_args;
global $prdctfltr_global;
$prdctfltr_global['ajax_paged'] = $res_paged;
$prdctfltr_global['posts_per_page'] = $columns*$rows;
$prdctfltr_global['active_filters'] = $curr_filters;
if ( $action !== '' ) {
$prdctfltr_global['action'] = $action;
}
if ( $preset !== '' ) {
$prdctfltr_global['preset'] = $preset;
}
if ( $disable_overrides !== '' ) {
$prdctfltr_global['disable_overrides'] = $disable_overrides;
}
$out = '';
global $woocommerce, $woocommerce_loop;
$woocommerce_loop['columns'] = $columns;
$products = new WP_Query( $args );
ob_start();
if ( $use_filter == 'yes' ) {
include_once( plugin_dir_path( __FILE__ ) . 'woocommerce/loop/orderby.php' );
}
if ( $products->have_posts() ) { ?>
<?php if ( $show_products == 'yes' ) { ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; ?>
<?php woocommerce_product_loop_end(); ?>
<?php
}
else {
$pagination = 'no';
}
?>
<?php
}
else if ( $_POST['pf_widget'] == 'yes' ) {
$prdctfltr_global['widget_search'] = $_POST['pf_widget'];
wc_get_template( 'loop/no-products-found.php' );
}
$shortcode = str_replace( ' type-product', ' product type-product', ob_get_clean() );
$out .= '<div' . ( $shortcode_id != '' ? ' id="'.$shortcode_id.'"' : '' ) . ' class="prdctfltr_sc_products woocommerce prdctfltr_ajax' . ( $class != '' ? ' '.$class.'' : '' ) . '"'.$margin.$add_ajax.'>';
$out .= do_shortcode($shortcode);
if ( $pagination == 'yes' ) {
ob_start();
?>
<nav class="woocommerce-pagination">
<?php
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
'base' => @add_query_arg('paged','%#%'),
'format' => '?page=%#%',
'current' => $res_paged,
'total' => $products->max_num_pages,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3
) ) );
?>
</nav>
<?php
$pagination = ob_get_clean();
$out .= $pagination;
}
$out .= '</div>';
die($out);
exit;
}
add_action('wp_ajax_nopriv_prdctfltr_respond', 'prdctfltr_respond' );
add_action('wp_ajax_prdctfltr_respond', 'prdctfltr_respond' );
/**
* Product Filter Action
*/
function prdctfltr_get_filter() {
include_once( plugin_dir_path( __FILE__ ) . 'woocommerce/loop/orderby.php' );
}
add_action('prdctfltr_output', 'prdctfltr_get_filter', 10);
/*
* [prdctfltr_sc_get_filter]
*/
function prdctfltr_sc_get_filter( $atts, $content = null ) {
return prdctfltr_get_filter();
}
add_shortcode( 'prdctfltr_sc_get_filter', 'prdctfltr_sc_get_filter' );
/*
* Product Filter Widget
*/
class prdctfltr extends WP_Widget {
function prdctfltr() {
$widget_ops = array(
'classname' => 'prdctfltr-widget',
'description' => __( 'Product Filter widget version.', 'wdgtcstmzr' )
);
$this->WP_Widget( 'prdctfltr', '+ Product Filter', $widget_ops );
}
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
global $prdctfltr_global;
$prdctfltr_global['widget_search'] = true;
$prdctfltr_global['widget_style'] = $instance['preset'];
$prdctfltr_global['preset'] = $instance['template'];
$prdctfltr_global['disable_overrides'] = ( isset( $instance['disable_overrides'] ) ? $instance['disable_overrides'] : 'false' );
if ( isset( $instance['widget_action'] ) && $instance['widget_action'] !== '' ) {
$prdctfltr_global['action'] = $instance['widget_action'];
}
echo $before_widget;
include( dirname( __FILE__ ) . '/woocommerce/loop/product-filter.php' );
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['preset'] = $new_instance['preset'];
$instance['template'] = $new_instance['template'];
$instance['disable_overrides'] = ( isset( $new_instance['disable_overrides'] ) ? $new_instance['disable_overrides'] : 'no' );
$instance['widget_action'] = $new_instance['widget_action'];
return $instance;
}
function form( $instance ) {
$vars = array( 'preset' => 'pf_default', 'template' => '', 'disable_overrides' => 'no', 'widget_action' => '' );
$instance = wp_parse_args( (array) $instance, $vars );
$preset = strip_tags($instance['preset']);
$template = strip_tags($instance['template']);
$disable_overrides = strip_tags($instance['disable_overrides']);
$widget_action = strip_tags($instance['widget_action']);
?>
<div>
<p class="prdctfltr-box">
<label for="<?php echo $this->get_field_id('preset'); ?>" class="prdctfltr-label"><?php _e('Style', 'prdctfltr'); ?> :</label>
<select name="<?php echo $this->get_field_name('preset'); ?>" id="<?php echo $this->get_field_id('preset'); ?>" class="widefat">
<option value="pf_default_inline"<?php echo ( $preset == 'pf_default_inline' ? ' selected="selected"' : '' ); ?>><?php _e('Flat Inline', 'prdctfltr'); ?></option>
<option value="pf_default"<?php echo ( $preset == 'pf_default' ? ' selected="selected"' : '' ); ?>><?php _e('Flat Block', 'prdctfltr'); ?></option>
<option value="pf_default_select"<?php echo ( $preset == 'pf_default_select' ? ' selected="selected"' : '' ); ?>><?php _e('Flat Select', 'prdctfltr'); ?></option>
</select>
</p>
<p class="prdctfltr-box">
<label for="<?php echo $this->get_field_id('template'); ?>" class="prdctfltr-label"><?php _e('Preset', 'prdctfltr'); ?> :</label>
<select name="<?php echo $this->get_field_name('template'); ?>" id="<?php echo $this->get_field_id('template'); ?>" class="widefat">
<option value="default"<?php echo ( $template == 'default' ? ' selected="selected"' : '' ); ?>><?php _e('Default', 'prdctfltr'); ?></option>
<?php
$curr_templates = get_option( 'prdctfltr_templates', array() );
foreach ( $curr_templates as $k => $v ) {
?>
<option value="<?php echo $k; ?>"<?php echo ( $template == $k ? ' selected="selected"' : '' ); ?>><?php echo $k; ?></option>
<?php
}
?>
</select>
</p>
<p class="prdctfltr-box">
<label for="<?php echo $this->get_field_id('disable_overrides'); ?>" class="prdctfltr-label"><?php _e('Disable Overrides', 'prdctfltr'); ?> :</label>
<input type="checkbox" name="<?php echo $this->get_field_name('disable_overrides'); ?>" id="<?php echo $this->get_field_id('disable_overrides'); ?>" value="yes" <?php echo ( $disable_overrides == 'yes' ? ' checked' : '' ); ?> />
</p>
<p class="prdctfltr-box">
<label for="<?php echo $this->get_field_id('widget_action'); ?>" class="prdctfltr-label"><?php _e('Widget Action URL', 'prdctfltr'); ?> :</label>
<input type="text" name="<?php echo $this->get_field_name('widget_action'); ?>" id="<?php echo $this->get_field_id('widget_action'); ?>" value="<?php echo $widget_action; ?>" class="widefat" /><br/>
<small><?php _e( 'Custom action is used if the widget is not used in shop, product archives or pages with Product Filter shortcodes. This way you can redirect filtering to your shop page or a custom page. Enter URL to redirect. For example your shop page URL', 'prdctfltr' ); ?> <?php echo get_permalink( prdctfltr_wpml_get_id ( woocommerce_get_page_id( 'shop' ) ) ); ?></small>
</p>
</div>
<?php
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("prdctfltr");' ) );
/**
* Widget AJAX Respond
*/
function prdctfltr_widget_respond() {
if ( isset($_POST['pf_filters']) ) {
foreach( $_POST['pf_filters'] as $k => $v ) {
$_GET[$k] = $v;
}
}
global $prdctfltr_global;
$shortcode_params = explode('|', $_POST['pf_shortcode']);
$columns = ( $shortcode_params[1] !== 'false' ? $shortcode_params[1] : 4 );
$rows = ( $shortcode_params[2] !== 'false' ? $shortcode_params[2] : 4 );
$prdctfltr_global['posts_per_page'] = $columns*$rows;
if ( isset($_POST['pf_widget_title']) ) {
$curr_title = explode('%%%', $_POST['pf_widget_title']);
}
if ( empty( $_GET ) ) {
parse_str(html_entity_decode($_POST['pf_query']), $pf_args);
$prdctfltr_global['sc_query'] = $pf_args;
}
ob_start();
the_widget('prdctfltr', 'preset=' . $_POST['pf_preset'] . '&template=' . $_POST['pf_template'], array('before_title'=>stripslashes($curr_title[0]),'after_title'=>stripslashes($curr_title[1])) );
$out = ob_get_clean();
die($out);
exit;
}
add_action('wp_ajax_nopriv_prdctfltr_widget_respond', 'prdctfltr_widget_respond' );
add_action('wp_ajax_prdctfltr_widget_respond', 'prdctfltr_widget_respond' );
/**
* Product Filter Get Between
*/
function prdctfltr_get_between( $content, $start, $end ){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
/**
* Product Filter Sort by Number
*/
function prdctfltr_sort_terms_naturally( $terms, $args ) {
$sort_terms = array();
foreach($terms as $term) {
$sort_terms[$term->name] = $term;
}
uksort( $sort_terms, 'strnatcmp');
if ( strtolower( $args['order'] ) == 'DESC' ) {
$sort_terms = array_reverse( $sort_terms );
}
return $sort_terms;
}
/**
* WPML IDs Support
*/
function prdctfltr_wpml_get_id($id) {
if( function_exists('icl_object_id') ) {
return icl_object_id($id,'page',true);
}
else {
return $id;
}
}
/**
* Product Filter Redirects
*/
$curr_cat_query = get_option( 'wc_settings_prdctfltr_force_categories', 'no' );
if ( !is_admin() && $curr_cat_query == 'no' ) {
if ( get_option( 'permalink_structure' ) !== '' ) {
function prdctfltr_redirect() {
if ( is_post_type_archive( 'product' ) || is_tax( get_object_taxonomies( 'product' ) ) ) {
if ( isset( $_REQUEST['product_cat'] ) ) {
$permalinks = get_option( 'woocommerce_permalinks' );
if ( strpos( $_REQUEST['product_cat'], ',' ) || strpos( $_REQUEST['product_cat'], '+' ) ) {
global $wp_rewrite;
$redirect = $wp_rewrite->get_extra_permastruct('product_cat');
$redirect = str_replace( '%product_cat%', $_REQUEST['product_cat'], $redirect);
}
else {
$redirect = get_term_link( $_REQUEST['product_cat'], 'product_cat' );
}
if ( substr( $redirect, -1 ) != '/' ) {
$redirect .= '/';
}
unset( $_REQUEST['product_cat'] );
if ( !empty( $_REQUEST ) ) {
$req = '';
foreach( $_REQUEST as $k => $v ) {
if ( strpos($v, ',') ) {
$new_v = str_replace(',', '%2C', $v);
}
else if ( strpos($v, '+') ) {
$new_v = str_replace('+', '%2B', $v);
}
else {
$new_v = $v;
}
$req .= $k . '=' . $new_v . '&';
}
$redirect = $redirect . '?' . $req;
}
exit( wp_redirect( $redirect ) );
}
}
}
add_action( 'template_redirect', 'prdctfltr_redirect', 999 );
}
function prdctfltr_redirect_empty_shop() {
$curr_display_disable = get_option( 'wc_settings_prdctfltr_disable_display', array( 'subcategories' ) );
if ( !empty( $_REQUEST ) && ( !empty( $_GET ) && !isset($_GET['lang']) ) && is_shop() && !is_product_category() && in_array( get_option( 'woocommerce_shop_page_display' ), $curr_display_disable ) ) {
$_REQUEST = array();
$redirect = get_permalink( prdctfltr_wpml_get_id( wc_get_page_id( 'shop' ) ) );
if ( substr( $redirect, -1 ) != '/' ) {
$redirect .= '/';
}
remove_action( 'template_redirect', 'prdctfltr_redirect', 999 );
exit( wp_redirect( $redirect ) );
}
else if ( !empty( $_REQUEST ) && ( !empty( $_GET ) && !isset($_GET['lang']) ) && is_post_type_archive( 'product' ) || is_tax( get_object_taxonomies( 'product' ) ) ) {
if ( isset( $_REQUEST['product_cat'] ) ) {
if ( count($_REQUEST) == 1 ) return;
$term = term_exists( $_REQUEST['product_cat'], 'product_cat' );
if ($term !== 0 && $term !== null) {
$display_type = get_woocommerce_term_meta( $term['term_id'], 'display_type', true );
$display_type = ( $display_type == '' ? get_option( 'woocommerce_category_archive_display' ) : $display_type );
if ( in_array( $display_type, $curr_display_disable ) ) {
$redirect = get_term_link( $_REQUEST['product_cat'], 'product_cat' );
$_REQUEST = array( 'product_cat', $_REQUEST['product_cat'] );
remove_action( 'template_redirect', 'prdctfltr_redirect', 999 );
exit( wp_redirect( $redirect ) );
}
}
}
}
}
add_action( 'template_redirect', 'prdctfltr_redirect_empty_shop', 998 );
}
/**
* Admin
*/
if ( is_admin() ) {
/*
* AJAX Save Preset
*/
function prdctfltr_admin_save() {
$curr_name = $_POST['curr_name'];
$curr_data = array();
$curr_data[$curr_name] = $_POST['curr_settings'];
$curr_presets = get_option('prdctfltr_templates');
if ( $curr_presets === false ) {
$curr_presets = array();
}
if ( isset($curr_presets) && is_array($curr_presets) ) {
if ( array_key_exists($curr_name, $curr_presets) ) {
unset($curr_presets[$curr_name]);
}
$curr_presets = $curr_presets + $curr_data;
update_option('prdctfltr_templates', $curr_presets);
die('1');
exit;
}
die();
exit;
}
add_action( 'wp_ajax_prdctfltr_admin_save', 'prdctfltr_admin_save' );
/*
* AJAX Load Preset
*/
function prdctfltr_admin_load() {
$curr_name = $_POST['curr_name'];
$curr_presets = get_option('prdctfltr_templates');
if ( isset($curr_presets) && !empty($curr_presets) && is_array($curr_presets) ) {
if ( array_key_exists($curr_name, $curr_presets) ) {
die(stripslashes($curr_presets[$curr_name]));
exit;
}
die('1');
exit;
}
die();
exit;
}
add_action( 'wp_ajax_prdctfltr_admin_load', 'prdctfltr_admin_load' );
/*
* AJAX Delete Preset
*/
function prdctfltr_admin_delete() {
$curr_name = $_POST['curr_name'];
$curr_presets = get_option('prdctfltr_templates');
if ( isset($curr_presets) && !empty($curr_presets) && is_array($curr_presets) ) {
if ( array_key_exists($curr_name, $curr_presets) ) {
unset($curr_presets[$curr_name]);
update_option('prdctfltr_templates', $curr_presets);
}
die('1');
exit;
}
die();
exit;
}
add_action( 'wp_ajax_prdctfltr_admin_delete', 'prdctfltr_admin_delete' );
/*
* AJAX Override Add
*/
function prdctfltr_or_add() {
$curr_tax = $_POST['curr_tax'];
$curr_term = $_POST['curr_term'];
$curr_override = $_POST['curr_override'];
$curr_overrides = get_option('prdctfltr_overrides');
if ( $curr_overrides === false ) {
$curr_overrides = array();
}
$curr_data = array(
$curr_tax => array( $curr_term => $curr_override )
);
if ( isset($curr_overrides) && is_array($curr_overrides) ) {
if ( isset($curr_overrides[$curr_tax]) && isset($curr_overrides[$curr_tax][$curr_term])) {
unset($curr_overrides[$curr_tax][$curr_term]);
}
$curr_overrides = array_merge_recursive($curr_overrides, $curr_data);
update_option('prdctfltr_overrides', $curr_overrides);
die('1');
exit;
}
die();
exit;
}
add_action( 'wp_ajax_prdctfltr_or_add', 'prdctfltr_or_add' );
/*
* AJAX Override Remove
*/
function prdctfltr_or_remove() {
$curr_tax = $_POST['curr_tax'];
$curr_term = $_POST['curr_term'];
$curr_overrides = get_option('prdctfltr_overrides');
if ( $curr_overrides === false ) {
$curr_overrides = array();
}
if ( isset($curr_overrides) && is_array($curr_overrides) ) {
if ( isset($curr_overrides[$curr_tax]) && isset($curr_overrides[$curr_tax][$curr_term])) {
unset($curr_overrides[$curr_tax][$curr_term]);
update_option('prdctfltr_overrides', $curr_overrides);
die('1');
exit;
}
}
die();
exit;
}
add_action( 'wp_ajax_prdctfltr_or_remove', 'prdctfltr_or_remove' );
/*
* AJAX Advanced Taxonomies
*/
function prdctfltr_c_fields() {
$taxonomies = get_object_taxonomies( 'product', 'object' );
$pf_id = ( isset( $_POST['pf_id'] ) ? $_POST['pf_id'] : 0 );
$html = '';
$html .= sprintf( '<label><span>%2$s</span> <input type="text" name="pfa_title[%3$s]" value="%1$s" /></label>', ( isset($_POST['pfa_title']) ? $_POST['pfa_title'] : '' ), __( 'Override title', 'prdctfltr' ), $pf_id );
$html .= '<label><span>' . __( 'Select taxonomy','prdctfltr' ) . '</span> <select class="prdctfltr_adv_select" name="pfa_taxonomy[' . $pf_id . ']">';
$i=0;
foreach ( $taxonomies as $k => $v ) {
if ( $k == 'product_type' ) {
continue;
}
$selected = ( isset($_POST['pfa_taxonomy']) && $_POST['pfa_taxonomy'] == $k ? ' selected="selected"' : '' ) ;
$html .= '<option value="' . $k . '"' . $selected . '>' . $v->label . '</option>';
if ( !isset($_POST['pfa_taxonomy']) && $i==0 ) {
$curr_fix = $k;
}
$i++;
}
if ( isset($_POST['pfa_taxonomy']) ) {
$curr_fix = $_POST['pfa_taxonomy'];
}
$html .= '</select></label>';
$catalog_attrs = get_terms( $curr_fix );
$curr_options = '';
if ( !empty( $catalog_attrs ) && !is_wp_error( $catalog_attrs ) ){
foreach ( $catalog_attrs as $term ) {
$selected = ( isset($_POST['pfa_include']) && is_array($_POST['pfa_include']) && in_array($term->slug, $_POST['pfa_include']) ? ' selected="selected"' : '' ) ;
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $term->slug, $term->name, $selected );
}
}
$html .= sprintf( '<label><span>%2$s</span> <select name="pfa_include[%3$s][]" multiple="multiple">%1$s</select></label>', $curr_options, __( 'Include terms', 'prdctfltr' ), $pf_id );
$curr_options = '';
$orderby_params = array(
'' => __( 'None', 'prdctfltr' ),
'id' => __( 'ID', 'prdctfltr' ),
'name' => __( 'Name', 'prdctfltr' ),
'number' => __( 'Number', 'prdctfltr' ),
'slug' => __( 'Slug', 'prdctfltr' ),
'count' => __( 'Count', 'prdctfltr' )
);
foreach ( $orderby_params as $k => $v ) {
$selected = ( isset($_POST['pfa_orderby']) && $_POST['pfa_orderby'] == $k ? ' selected="selected"' : '' );
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected );
}
$html .= sprintf( '<label><span>%3$s</span> <select name="pfa_orderby[%2$s]">%1$s</select></label>', $curr_options, $pf_id, __( 'Term order by', 'prdctfltr' ) );
$curr_options = '';
$order_params = array(
'ASC' => __( 'ASC', 'prdctfltr' ),
'DESC' => __( 'DESC', 'prdctfltr' )
);
foreach ( $order_params as $k => $v ) {
$selected = ( isset($pf_filters_advanced['pfa_order'][$pf_id]) && $pf_filters_advanced['pfa_order'][$pf_id] == $k ? ' selected="selected"' : '' );
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected );
}
$html .= sprintf( '<label><span>%3$s</span> <select name="pfa_order[%2$s]"%4$s>%1$s</select></label>', $curr_options, $pf_id, __( 'Term order', 'prdctfltr' ), $add_disable );
$selected = ( isset($_POST['pfa_multiselect']) && $_POST['pfa_multiselect'] == 'yes' ? ' checked="checked"' : '' ) ;
$html .= sprintf( '<label><input type="checkbox" name="pfa_multiselect[%3$s]" value="yes"%1$s /> %2$s</label>', $selected, __( 'Use multi select', 'prdctfltr' ), $pf_id );
$curr_options = '';
$relation_params = array(
'IN' => __( 'Filtered products have at least one term (IN)', 'prdctfltr' ),
'AND' => __( 'Filtered products have selected terms (AND)', 'prdctfltr' )
);
foreach ( $relation_params as $k => $v ) {
$selected = ( isset($_POST['pfa_relation']) && $_POST['pfa_relation'] == $k ? ' selected="selected"' : '' );
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected );
}
$html .= sprintf( '<label><span>%3$s</span> <select name="pfa_relation[%2$s]">%1$s</select></label>', $curr_options, $i, __( 'Term relation', 'prdctfltr' ) );
$selected = ( isset($_POST['pfa_adoptive']) && $_POST['pfa_adoptive'] == 'yes' ? ' checked="checked"' : '' ) ;
$html .= sprintf( '<label><input type="checkbox" name="pfa_adoptive[%3$s]" value="yes"%1$s /> %2$s</label>', $selected, __( 'Use adoptive filtering', 'prdctfltr' ), $pf_id );
$selected = ( isset($_POST['pfa_none']) && $_POST['pfa_none'] == 'yes' ? ' checked="checked"' : '' ) ;
$html .= sprintf( '<label><input type="checkbox" name="pfa_none[%3$s]" value="yes"%1$s /> %2$s</label>', $selected, __( 'Hide none', 'prdctfltr' ), $pf_id );
die($pf_id . '%SPLIT%' . $html);
exit;
}
add_action( 'wp_ajax_prdctfltr_c_fields', 'prdctfltr_c_fields' );
/**
* AJAX Advanced Terms
*/
function prdctfltr_c_terms() {
$curr_tax = ( isset($_POST['taxonomy']) ? $_POST['taxonomy'] : '' );
if ( $curr_tax == '' ) {
die();
exit;
}
$html = '';
$catalog_attrs = get_terms( $curr_tax );
$curr_options = '';
if ( !empty( $catalog_attrs ) && !is_wp_error( $catalog_attrs ) ){
foreach ( $catalog_attrs as $term ) {
$curr_options .= sprintf( '<option value="%1$s">%2$s</option>', $term->slug, $term->name );
}
}
$html .= sprintf( '<label><span>%2$s</span> <select name="pfa_include[%%%%][]" multiple="multiple">%1$s</select></label>', $curr_options, __( 'Include terms', 'prdctfltr' ) );
die($html);
exit;
}
add_action( 'wp_ajax_prdctfltr_c_terms', 'prdctfltr_c_terms' );
/**
* AJAX Range Taxonomies
*/
function prdctfltr_r_fields() {
$taxonomies = wc_get_attribute_taxonomies();
$pf_id = ( isset( $_POST['pf_id'] ) ? $_POST['pf_id'] : 0 );
$html = '';
$html .= sprintf( '<label><span>%2$s</span> <input type="text" name="pfr_title[%3$s]" value="%1$s" /></label>', ( isset($_POST['pfr_title']) ? $_POST['pfr_title'] : '' ), __( 'Override title', 'prdctfltr' ), $pf_id );
$html .= '<label><span>' . __( 'Select attribute','prdctfltr' ) . '</span> <select class="prdctfltr_rng_select" name="pfr_taxonomy[' . $pf_id . ']">';
$html .= '<option value="price"' . ( isset($_POST['pfr_taxonomy']) && $_POST['pfr_taxonomy'] == 'price' ? ' selected="selected"' : '' ) . '>' . __( 'Price range', 'prdctfltr' ) . '</option>';
foreach ( $taxonomies as $k => $v ) {
$selected = ( isset($_POST['pfr_taxonomy']) && $_POST['pfr_taxonomy'] == 'pa_' . $v->attribute_name ? ' selected="selected"' : '' ) ;
$curr_label = !empty( $v->attribute_label ) ? $v->attribute_label : $v->attribute_name;
$html .= '<option value="pa_' . $v->attribute_name . '"' . $selected . '>' . $curr_label . '</option>';
}
if ( isset($_POST['pfr_taxonomy']) ) {
$curr_fix = $_POST['pfr_taxonomy'];
}
else {
$curr_fix = 'price';
}
$html .= '</select></label>';
if ( $curr_fix == 'price' ) {
$html .= sprintf( '<label><span>%2$s</span> <select name="pfr_include[%3$s][]" multiple="multiple" disabled>%1$s</select></label>', array(), __( 'Include terms', 'prdctfltr' ), $pf_id );
$add_disable = ' disabled';
}
else {
$catalog_attrs = get_terms( $curr_fix );
$curr_options = '';
if ( !empty( $catalog_attrs ) && !is_wp_error( $catalog_attrs ) ){
foreach ( $catalog_attrs as $term ) {
$selected = ( isset($_POST['pfr_include']) && is_array($_POST['pfr_include']) && in_array($term->slug, $_POST['pfr_include']) ? ' selected="selected"' : '' ) ;
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $term->slug, $term->name, $selected );
}
}
$html .= sprintf( '<label><span>%2$s</span> <select name="pfr_include[%3$s][]" multiple="multiple">%1$s</select></label>', $curr_options, __( 'Include terms', 'prdctfltr' ), $pf_id );
$add_disable = '';
}
$curr_options = '';
$orderby_params = array(
'' => __( 'None', 'prdctfltr' ),
'id' => __( 'ID', 'prdctfltr' ),
'name' => __( 'Name', 'prdctfltr' ),
'number' => __( 'Number', 'prdctfltr' ),
'slug' => __( 'Slug', 'prdctfltr' ),
'count' => __( 'Count', 'prdctfltr' )
);
foreach ( $orderby_params as $k => $v ) {
$selected = ( isset($_POST['pfr_orderby']) && $_POST['pfr_orderby'] == $k ? ' selected="selected"' : '' );
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected );
}
$html .= sprintf( '<label><span>%3$s</span> <select name="pfr_orderby[%2$s]"%4$s>%1$s</select></label>', $curr_options, $pf_id, __( 'Term order by', 'prdctfltr' ), $add_disable );
$curr_options = '';
$order_params = array(
'ASC' => __( 'ASC', 'prdctfltr' ),
'DESC' => __( 'DESC', 'prdctfltr' )
);
foreach ( $order_params as $k => $v ) {
$selected = ( isset($pf_filters_advanced['pfr_order'][$pf_id]) && $pf_filters_advanced['pfr_order'][$pf_id] == $k ? ' selected="selected"' : '' );
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected );
}
$html .= sprintf( '<label><span>%3$s</span> <select name="pfr_order[%2$s]"%4$s>%1$s</select></label>', $curr_options, $pf_id, __( 'Term order', 'prdctfltr' ), $add_disable );
$catalog_style = array( 'flat' => __( 'Flat', 'prdctfltr' ), 'modern' => __( 'Modern', 'prdctfltr' ), 'html5' => __( 'HTML5', 'prdctfltr' ), 'white' => __( 'White', 'prdctfltr' ) );
$curr_options = '';
foreach ( $catalog_style as $k => $v ) {
$selected = ( isset($_POST['pfr_style']) && $_POST['pfr_style'] == $k ? ' selected="selected"' : '' ) ;
$curr_options .= sprintf( '<option value="%1$s"%3$s>%2$s</option>', $k, $v, $selected );
}
$html .= sprintf( '<label><span>%2$s</span> <select name="pfr_style[%3$s]">%1$s</select></label>', $curr_options, __( 'Select style', 'prdctfltr' ), $pf_id );
$selected = ( isset($_POST['pfr_grid']) && $_POST['pfr_grid'] == 'yes' ? ' checked="checked"' : '' ) ;
$html .= sprintf( '<label><input type="checkbox" name="pfr_grid[%3$s]" value="yes"%1$s /> %2$s</label>', $selected, __( 'Use grid', 'prdctfltr' ), $pf_id );
die($pf_id . '%SPLIT%' . $html);
exit;
}
add_action( 'wp_ajax_prdctfltr_r_fields', 'prdctfltr_r_fields' );
/**
* AJAX Range Terms
*/
function prdctfltr_r_terms() {
$curr_tax = ( isset($_POST['taxonomy']) ? $_POST['taxonomy'] : '' );
if ( $curr_tax == '' ) {
die();
exit;
}
$html = '';
if ( !in_array( $curr_tax, array( 'price' ) ) ) {
$catalog_attrs = get_terms( $curr_tax );
$curr_options = '';
if ( !empty( $catalog_attrs ) && !is_wp_error( $catalog_attrs ) ){
foreach ( $catalog_attrs as $term ) {
$curr_options .= sprintf( '<option value="%1$s">%2$s</option>', $term->slug, $term->name );
}
}
$html .= sprintf( '<label><span>%2$s</span> <select name="pfr_include[%%%%][]" multiple="multiple">%1$s</select></label>', $curr_options, __( 'Include terms', 'prdctfltr' ) );
}
else {
$html .= sprintf( '<label><span>%1$s</span> <select name="pfr_include[%%%%][]" multiple="multiple" disabled></select></label>', __( 'Include terms', 'prdctfltr' ) );
}
die($html);
exit;
}
add_action( 'wp_ajax_prdctfltr_r_terms', 'prdctfltr_r_terms' );
/**
* Product Filter Settings
*/
include_once ( $curr_path . '/lib/pf-settings.php' );
/**
* Product Filter Thumbnails Include
*/
include_once ( $curr_path . '/lib/pf-attribute-thumbnails.php' );
}
?>