FCHubFCHub.co

Developer Reference

REST API endpoints, WordPress hooks, PHP API, feature flags, order metadata, and database schema for FCHub Multi-Currency.

Everything a developer needs to extend, integrate with, or debug FCHub Multi-Currency.

REST API

All endpoints use the fchub-mc/v1 namespace. Admin endpoints require manage_options capability and a valid X-WP-Nonce header.

Public Endpoints

Returns the current resolved currency context.

Response:

{
  "display_currency": {
    "code": "EUR",
    "name": "Euro",
    "symbol": "€",
    "decimals": 2,
    "position": "right_space"
  },
  "base_currency": {
    "code": "USD",
    "name": "US Dollar",
    "symbol": "$",
    "decimals": 2,
    "position": "left"
  },
  "rate": "0.92140000",
  "source": "cookie",
  "is_base_display": false
}

Admin Endpoints

All require manage_options and nonce verification.

Returns all plugin settings with defaults merged.

WordPress Hooks

Actions (fired by the plugin)

HookArgumentsDescription
fchub_mc/context_switchedstring $currencyCode, int $userIdFired when a user selects a new currency. $userId is 0 for guests.
fchub_mc/rates_refreshedstring $baseCurrency, int $countFired after a successful rate refresh.
fchub_mc/community_currency_updatedstring $currencyCode, int $userIdFired after FluentCommunity user meta is written.

Filters (fired by the plugin)

HookArgumentsDescription
fchub_mc/modulesarray $modulesModify the list of modules before registration. Add or remove module classes.
fchub_mc/contextCurrencyContext $contextOverride the resolved currency context. Runs after the resolver chain.

Hooks consumed (FluentCart)

HookTypeDescription
fluent_cart/integration/addonsfilterRegisters the plugin as a FluentCart addon
fluent_cart/checkout/after_patch_checkout_data_fragmentsfilterInjects disclosure text into checkout fragments
fluent_cart/order_paid_doneactionTriggers order snapshot and FluentCRM sync
fluent_cart/store_settings/valuesfilterAdds multi-currency fields to store settings API
fluent_cart/loading_appactionEnqueues admin JS bundle

PHP API

fchub_mc_format_price(float $basePrice): string

Converts a base-currency price to the visitor's display currency and returns formatted HTML.

echo fchub_mc_format_price(99.99);
// Output: "€92.14" (when display currency is EUR with rate 0.9214)

Falls back to FluentCart's native formatter when the plugin is disabled or the visitor is in the base currency. Uses bcmul for precision when bcmath is available.

JavaScript Globals

// Switch currency programmatically (REST call + page reload)
window.fchubMcSwitchCurrency('EUR');

// Re-initialise all switcher widgets after dynamic content load
window.fchubMcInitSwitchers();

// Re-project prices on a specific DOM subtree
window.fchubMcProjectPrices(document.getElementById('my-container'));

JavaScript Events

EventTargetDescription
fchub_mc:context_changeddocumentFired before page reload after currency switch
fchub_mc:prices_projecteddocumentFired after each projection pass

Currency Switcher Widget

Block Family

The plugin now exposes a small set of currency-related blocks:

  • fchub-multi-currency/switcher
  • fchub-multi-currency/current-currency
  • fchub-multi-currency/exchange-rate
  • fchub-multi-currency/context-notice
  • fchub-multi-currency/selector-buttons

CSS Custom Properties

Override these on .fchub-mc-switcher to theme the widget:

.fchub-mc-switcher {
  --fchub-mc-radius: 6px;
  --fchub-mc-border-color: #d0d5dd;
  --fchub-mc-bg: #fff;
  --fchub-mc-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  --fchub-mc-transition: 150ms ease;
  --fchub-mc-badge-ok: #12b76a;
  --fchub-mc-badge-stale: #f04438;
}

ARIA Roles

The widget implements the combobox/listbox pattern:

  • Trigger: role="combobox" with aria-expanded, aria-haspopup="listbox", aria-controls
  • Option list: role="listbox" with aria-label="Select currency"
  • Each option: role="option" with aria-selected on the active currency
  • aria-activedescendant tracks the currently focused option
  • Unique ARIA IDs per instance for multiple widgets on one page

JavaScript Configuration Object

The fchubMcConfig object is injected via wp_localize_script and available globally:

KeyTypeDescription
ratestringCurrent exchange rate
displayCurrencystringDisplay currency code
baseCurrencystringBase currency code
decimalsintDisplay currency decimal places
symbolstringDisplay currency symbol
positionstringSymbol position (left, right, left_space, right_space)
isBaseDisplayboolWhether display equals base
roundingModestringRounding mode slug
roundingPrecisionintRounding precision
restUrlstringREST API base URL
noncestringWP REST nonce
currenciesarrayAll display currencies with flags
baseCurrencySignstringBase currency symbol
baseCurrencyPositionstringBase currency symbol position
baseCurrencyCodestringBase currency ISO code
baseDecimalSepstringBase currency decimal separator
baseThousandSepstringBase currency thousand separator
baseDecimalsintBase currency decimal places
disclosureEnabledboolWhether checkout disclosure is active
disclosureTextstring|nullRendered disclosure text with tokens replaced

Feature Flags

Internal flags stored under the fchub_mc_feature_flags option. Not exposed in the settings UI — visible in the Diagnostics tab.

FlagDefaultControls
js_projectiontrueWhether currency-projection.js is enqueued. Disable to turn off client-side price rewriting.
geo_resolverfalseWhether the geolocation resolver is included in the chain. Not yet production-ready.

Order Metadata

Written by SaveOrderSnapshotAction on fluent_cart/order_paid_done. Only written when the display currency differs from base.

Meta KeyTypeDescription
_fchub_mc_display_currencystringISO 4217 display currency code at time of order
_fchub_mc_base_currencystringISO 4217 base currency code
_fchub_mc_ratestringExchange rate (8 decimal places)
_fchub_mc_disclosure_versionstringPlugin version string

Database Schema

fchub_mc_rate_history

ColumnTypeNotes
idBIGINT UNSIGNED AUTO_INCREMENTPrimary key
base_currencyCHAR(3)ISO 4217
quote_currencyCHAR(3)ISO 4217
rateDECIMAL(18,8)Exchange rate
providerVARCHAR(64)Provider slug, default manual
fetched_atDATETIMEWordPress site timezone

Indexes: base_quote_fetched (base_currency, quote_currency, fetched_at), fetched_at

Pruned automatically: rows older than 90 days are deleted by the cron job.

fchub_mc_event_log

ColumnTypeNotes
idBIGINT UNSIGNED AUTO_INCREMENTPrimary key
eventVARCHAR(128)Event name
user_idBIGINT UNSIGNED NULLWordPress user ID
ip_hashVARCHAR(64) NULLHashed IP address
payloadLONGTEXT NULLJSON payload
created_atDATETIMETimestamp

Indexes: event_created (event, created_at), user_id

Used by the GDPR personal data exporter/eraser.

GDPR / Privacy

The plugin registers with WordPress's privacy tools:

Personal Data Exporter

Exports for a given email address:

  • User meta _fchub_mc_currency (preferred currency preference)
  • All fchub_mc_event_log rows for the user (event name, timestamp; paginated at 50 per page)

Personal Data Eraser

Deletes for a given email address:

  • _fchub_mc_currency user meta
  • All fchub_mc_event_log rows for the user

Constants Reference

All constants are defined in FChubMultiCurrency\Support\Constants:

ConstantValueUsage
REST_NAMESPACEfchub-mc/v1REST API namespace
OPTION_SETTINGSfchub_mc_settingsMain settings option key
OPTION_DB_VERSIONfchub_mc_db_versionDB migration tracking
OPTION_FEATURE_FLAGSfchub_mc_feature_flagsFeature flag storage
HOOK_PREFIXfchub_mc/Internal action/filter prefix
COOKIE_KEYfchub_mc_currencyBrowser cookie name
COOKIE_DAYS90Default cookie lifetime
USER_META_KEY_fchub_mc_currencyWP user meta key
TABLE_RATE_HISTORYfchub_mc_rate_historyRate history table (without prefix)
TABLE_EVENT_LOGfchub_mc_event_logEvent log table (without prefix)
FC_ADDON_SLUGfchub-multi-currencyFluentCart addon registration slug
CRON_REFRESH_RATESfchub_mc_refresh_ratesWP cron event name

On this page