Hi,
I finally resolved this issue partially, I modified the code from “WooCommerce Product Price Based on Countries”, which supports price filter. The code is to be included into class-wcj-price-by-country-core.php. I wrote it specifically for my site rockngemshow.com, so it does not work in general (one global and one local currency, max and min fixed, but different for each currency). It would be great if jetpack developers could generalize the code and input it into plugin, woocommerce price filter is great widget but with price-by-country it becomes completely useless.
Regards,
David
This goes into function add_hooks()
add_filter( ‘woocommerce_price_filter_results’, array( $this , ‘price_filter_results’ ), 10, 3 );
add_filter( ‘woocommerce_price_filter_widget_min_amount’, array( $this , ‘price_filter_widget_min_amount’ ) );
add_filter( ‘woocommerce_price_filter_widget_max_amount’, array( $this , ‘price_filter_widget_max_amount’ ) );
These are new functions in class WCJ_Price_by_Country_Core
/**
* Return matched produts where price between min and max
*
* @param array $matched_products_query
* @param int $min
* @param int $max
* @return array
*/
public function price_filter_results( $matched_products_query, $min, $max ){
global $wpdb;
$country_exchange_rate = 1;
$group_id = $this->get_customer_country_group_id();
if ( null == $group_id ) $group_id=-1;
if ( $group_id > 0 ) $country_exchange_rate = get_option( ‘wcj_price_by_country_exchange_rate_group_’ . $group_id, 1 );
if($group_id < 0 ) {if($max==200) $max=1000000;}
else if ($group_id == 1 ) {if($max==5000) $max=1000000;}
$sql = $wpdb->prepare(‘SELECT DISTINCT ID, post_parent, post_type FROM %1$s
INNER JOIN %2$s wc_price ON ID = wc_price.post_id AND wc_price.meta_key = “_price”
INNER JOIN %2$s wc_price_local_1 ON ID = wc_price_local_1.post_id AND wc_price_local_1.meta_key = “_wcj_price_by_country_regular_price_local_1”
WHERE post_type IN ( “product”, “product_variation” ) AND
IF(%6$d < 0,
wc_price.meta_value BETWEEN %4$d AND %5$d,
IF(wc_price_local_1.meta_value > 1,
wc_price_local_1.meta_value BETWEEN %4$d AND %5$d,
wc_price.meta_value * %3$d BETWEEN %4$d AND %5$d
)
)’
, $wpdb->posts, $wpdb->postmeta, $country_exchange_rate, $min, $max, $group_id);
$matched_products_query = $wpdb->get_results( $sql, OBJECT_K );
return $matched_products_query;
}
/**
* Filter for price_filter_widget_min_amount
* @param $amount Min amount
*/
public function price_filter_widget_min_amount( $amount ) {
$amount = 0;
return $amount;
}
/**
* Filter for price_filter_widget_max_amount
* @param $amount Max amount
*/
public function price_filter_widget_max_amount( $amount ) {
$group_id = $this->get_customer_country_group_id();
if($group_id == null ) $amount = 200;
else if ($group_id == 1 ) $amount = 5000;
return $amount;
}