Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active July 20, 2021 16:28
Show Gist options
  • Save plugin-republic/93a9a97c2329fea612c20bdc735d941d to your computer and use it in GitHub Desktop.
Save plugin-republic/93a9a97c2329fea612c20bdc735d941d to your computer and use it in GitHub Desktop.
<?php
function pewc_get_multicurrency_price( $price, $item, $product ) {
// Compatibility with WooCommerce multilingual
$price = apply_filters( 'wcml_raw_price_amount', $price );
if( class_exists('WOOCS') ) {
global $WOOCS;
if ($WOOCS->is_multiple_allowed) {
$price = $WOOCS->woocs_exchange_value( floatval( $price ) );
}
}
return $price;
}
add_filter( 'pewc_filter_field_price', 'pewc_get_multicurrency_price', 10, 3 );
add_filter( 'pewc_filter_option_price', 'pewc_get_multicurrency_price', 10, 3 );
@mattradford
Copy link

This worked for me once I'd added the additional $item parameter, otherwise my option prices all returned 0.

add_filter('pewc_filter_field_price', [$this, 'pewcGetMulticurrencyPrice'], 10, 2);
add_filter('pewc_filter_option_price', [$this, 'pewcGetMulticurrencyPrice'], 10, 2);

/**
     * Get price in chosen currency
     *
     * @link https://gist.github.com/plugin-republic/93a9a97c2329fea612c20bdc735d941d
     */
    public function pewcGetMulticurrencyPrice($price, $item) {

        if(class_exists('WOOCS')) {

                // Compatibility with WOOCS Currency Switcher
                $price = apply_filters('wcml_raw_price_amount', $price);

                global $WOOCS;
                if ($WOOCS->is_multiple_allowed) {
                    $price = $WOOCS->woocs_exchange_value(floatval($price));
                }

                return $price;

        }
    }
    ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment