Contents
On this page

Hooks and PHP helpers - Plugixa Multi Currency for WooCommerce

This page is for developers. It lists the PHP helpers a theme or plugin can call, and the WordPress actions and filters the plugin fires. Hooks marked PRO only exist when the Pro feature they belong to is active.

PHP helpers

Each helper is wrapped in function_exists(), so a site can define its own version first.

Function Returns
plugixa_mc_get_currency() The currency the visitor sees prices in now, for example "EUR". Always the store currency in wp-admin, cron and the REST API outside the shop.
plugixa_mc_get_currencies() Every enabled currency, store currency first, as code => [code, symbol, decimals, rate, is_store_currency].
plugixa_mc_convert( $amount, $to = null, $from = null, $context = 'price' ) An amount converted between your currencies, as a decimal string such as "18.95". $to defaults to the visitor’s currency, $from to the store currency. $context is price, shipping, fee or raw. Unknown currencies leave the amount unchanged.
plugixa_mc_price( $amount, $to = null, $args = array() ) A store-currency amount converted and formatted as HTML, like wc_price().

Conversions use the shop’s own rates, margins, rounding and, with Pro, charm endings.

// "From 25.00" in the visitor's currency, in a theme template.
echo 'From ' . plugixa_mc_price( 25 );

// A shipping threshold of 100 in the store currency, converted for the visitor.
$threshold = plugixa_mc_convert( 100, null, null, 'raw' );

// 50 GBP expressed in EUR.
$eur = plugixa_mc_convert( 50, 'EUR', 'GBP' );

Actions

Action Arguments Fires
plugixa_multi_currency_loaded Once the plugin is fully booted.
plugixa_multi_currency_switched $code, $source, $previous After a shopper’s currency is stored. $source says what made the choice: manual (the switcher), url, checkout… $previous is the currency stored before, or null.
plugixa_multi_currency_rates_updated $report After a rate update, with one line per currency (code, old and new rate, provider, status, message).
plugixa_multi_currency_currencies_changed $currencies After any currency is added, edited or removed, with every currency keyed by code.
plugixa_multi_currency_currency_deleted $code After a currency is removed.
plugixa_multi_currency_settings_saved $settings After the settings are saved.
plugixa_multi_currency_purge_page_cache After the plugin empties the page caches it knows. Hook it to purge a CDN, Varnish or a host cache.
plugixa_multi_currency_switcher_enqueue On a page that shows a switcher, after its stylesheet and script are enqueued. Enqueue the CSS of your own switcher style here.
plugixa_multi_currency_app_toggled $id, $enabled After an app is switched on or off in the App manager.
plugixa_multi_currency_activated / _deactivated On activation and deactivation.
plugixa_multi_currency_uninstall During uninstall, only when data is being erased, before the tables are dropped.
plugixa_multi_currency_register_rest_routes $namespace, $container When REST routes are registered, to add your own under plugixa-multi-currency/v1.

Filters: prices and checkout

Filter Arguments Use it to
plugixa_multi_currency_converted_amount $rounded, $exact, $currency, $context Change a converted amount after rounding. Pro’s charm endings use it.
plugixa_multi_currency_fixed_price $fixed, $product, $currency, $filter Return a fixed price for a product and currency, or null to convert. Pro’s fixed prices use it.
plugixa_multi_currency_convert_fee $convert, $fee, $cart, $currency Return false for a cart fee that must not be converted, such as a fee that is a percentage of the cart.
plugixa_multi_currency_checkout_in_base $in_base, $currency Force or stop checkout in the store currency for a currency.
plugixa_multi_currency_role_fixed_price PRO $price, $product, $roles, $code Change the fixed role price, or return null for none.

Example: keep a “card fee” of 2% of the cart from being converted a second time.

add_filter( 'plugixa_multi_currency_convert_fee', function ( $convert, $fee ) {
    return 'card-fee' === $fee->id ? false : $convert;
}, 10, 2 );

Filters: which currency the visitor sees

Filter Arguments Use it to
plugixa_multi_currency_active_currency $code Change the resolved currency of the request.
plugixa_multi_currency_detected_currency $code Detect a currency for a visitor who has not chosen one: return an enabled code, or null to keep looking. Pro’s detection uses it.
plugixa_multi_currency_detects_on_first_visit $detects Return true when your detection can show a first-time visitor another currency, so page caches are set up for it.
plugixa_multi_currency_country_currency_map PRO $map Change the country to currency map (ISO 3166-1 alpha-2 to ISO 4217).

Filters: switcher

Filter Arguments Use it to
plugixa_multi_currency_switcher_styles $labels Add a switcher style (style => name). It renders the list markup with the class pmc-switcher--{style}.
plugixa_multi_currency_switch_redirect $url, $code Change where a shopper is sent after switching without JavaScript.
plugixa_multi_currency_placement_switcher_args PRO $args, $context Change the style, label or flags of the automatic switchers (product or mini-cart).

Filters: rates

Filter Arguments Use it to
plugixa_multi_currency_rate_providers $providers Add or reorder rate providers (objects implementing the plugin’s provider interface).
plugixa_multi_currency_rates_interval $seconds Change how often automatic updates run. Daily by default; 15 minutes at the least.
plugixa_multi_currency_rate_decision $decision, $code, $old, $rate, $provider Return hold to keep a new rate for review instead of applying it.
plugixa_multi_currency_rate_history_keep $keep Change how many history entries are kept per currency (30).

Filters: caching, SEO and feeds

Filter Arguments Use it to
plugixa_multi_currency_cache_plugins $found Change the list of detected page cache plugins (id => name).
plugixa_multi_currency_cache_first $on Report that catalog pages are rendered once for the cache. Pro’s cache-first mode uses it.
plugixa_multi_currency_wcpay_conflict $active Return false to run alongside WooPayments Multi-Currency anyway.
plugixa_multi_currency_privacy_paragraphs $paragraphs Add paragraphs to the suggested privacy policy text.
plugixa_multi_currency_sitemap_currencies PRO $codes Choose the currencies listed in the XML sitemap.
plugixa_multi_currency_sitemap_sources PRO $sources Choose the post types and taxonomies copied per currency (default product, product_cat).
plugixa_multi_currency_feed_item PRO $item, $product, $code, $parent Change a Google Merchant feed item. Keys are Google attribute names without g:; return null to leave the product out.
plugixa_multi_currency_url_in_currency PRO $in_currency, $url, $code Change a product’s landing address for a currency in the feed.

Example: add the GTIN from a custom field to every feed item.

add_filter( 'plugixa_multi_currency_feed_item', function ( $item, $product ) {
    $gtin = $product->get_meta( '_gtin' );
    if ( $item && $gtin ) {
        $item['gtin'] = $gtin;
    }
    return $item;
}, 10, 2 );

Order data

The rate and store-currency totals saved on each order are order meta, readable with $order->get_meta(). See Orders and refunds for the keys.

Quick Links

Share