• Hi,

    I just found that the “Prices and Currencies by Country” do not work with Woocommerce build-in “Filter by Price” slider widget. While the changed price label (Euro, USD) correctly shows next to the slider, the amount is corresponding to the original currencies, leading to ridiculous results: shop items have by example prices 10-30 Euro, but the slider gives you range 250-750 Euro (the base currency is CZK which is 25 CZK per Euro).

    Is there a way to fix this?

    Thank you, David

    https://www.ads-software.com/plugins/woocommerce-jetpack/

Viewing 1 replies (of 1 total)
  • Thread Starter dmasin

    (@dmasin)

    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;
    }

Viewing 1 replies (of 1 total)
  • The topic ‘"Prices by Country" do not work with Woocommerce price filter’ is closed to new replies.