Skip Navigation

Open

Reported for: WooCommerce Multilingual & Multicurrency 5.1.2

Topic Tags: Bug

Overview of the issue

When using WooCommerce Multilingual’s multi-currency feature, the Filter per Price widget displays an inaccurate price range for secondary currencies. It always displays the default currency’s range.

Workaround

Please, be sure of making a full backup of your site before proceeding.

  • Add the following snippet in your theme’s functions.php file:
    use function WCML\functions\getClientCurrency;
    use function WPML\Container\make;
    
    add_filter( 'rest_request_after_callbacks', function( $response, $handler, $request ) {
    
    	if (
    		wcml_is_multi_currency_on()
    		&& 'GET' === $request->get_method()
    		&& 'products/collection-data' === substr( $request->get_route(), -24 )
    		&& ! empty( $request['calculate_price_range'] )
    	) {
    		$mc = make( \WCML_Multi_Currency::class );
    		$from_currency = $mc->get_default_currency();
    		$to_currency = getClientCurrency();
    		$data = $response->get_data();
    		$data['price_range']->min_price = $mc->prices->convert_price_amount( $mc->prices->unconvert_price_amount( $data['price_range']->min_price, $from_currency ), $to_currency );
    		$data['price_range']->max_price = $mc->prices->convert_price_amount( $mc->prices->unconvert_price_amount( $data['price_range']->max_price, $from_currency ), $to_currency );
    		$response->set_data( $data );
    	}
    
    	return $response;
    }, 10, 3 );
    

返答する

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

これらのタグを使用できます:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>