PHPackages                             arraypress/wp-currencies - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/wp-currencies

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/wp-currencies
========================

A comprehensive WordPress library for Stripe currency formatting, conversion, and validation supporting all 135 Stripe currencies.

042PHP

Since Feb 27Pushed 4mo agoCompare

[ Source](https://github.com/arraypress/wp-currencies)[ Packagist](https://packagist.org/packages/arraypress/wp-currencies)[ RSS](/packages/arraypress-wp-currencies/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Currencies
====================

[](#wordpress-currencies)

A comprehensive WordPress library for Stripe currency formatting and conversion, supporting all 136 Stripe currencies with proper decimal handling, locale-aware formatting, and country data.

Features
--------

[](#features)

- 💳 **All 136 Stripe Currencies** - Complete support for every Stripe-supported currency
- 🔢 **Smart Decimal Handling** - Correctly handles zero-decimal (JPY, KRW) and three-decimal (KWD, OMR) currencies
- 🌍 **Locale-Aware Formatting** - Customer-facing formatting with correct symbol position, separators, and spacing
- 🏳️ **Country Data** - ISO 3166-1 country codes and names for each currency with reverse lookup
- 💰 **Multiple Format Options** - Format with symbols, codes, or plain numbers
- 🔄 **Bidirectional Conversion** - Convert between decimal amounts and Stripe's smallest units
- ⚡ **Zero Dependencies** - Lightweight, only requires PHP 8.2+

Installation
------------

[](#installation)

```
composer require arraypress/wp-currencies
```

Basic Formatting
----------------

[](#basic-formatting)

```
use ArrayPress\Currencies\Currency;

// Format amount for display (amount is in cents)
echo Currency::format( 9999, 'USD' );  // $99.99
echo Currency::format( 9999, 'EUR' );  // €99.99
echo Currency::format( 9999, 'JPY' );  // ¥9,999 (zero-decimal)
echo Currency::format( 9999, 'KWD' );  // KD9.999 (three-decimal)

// Format without symbol
echo Currency::format_plain( 9999, 'USD' );  // 99.99

// Format with currency code
echo Currency::format_with_code( 9999, 'USD' );  // 99.99 USD
```

Locale-Aware Formatting
-----------------------

[](#locale-aware-formatting)

For customer-facing storefronts where correct symbol position and separators matter:

```
// Defaults to WordPress site locale (get_locale())
echo Currency::format_localized( 9999, 'USD' );  // $99.99
echo Currency::format_localized( 9999, 'EUR' );  // 99,99 €
echo Currency::format_localized( 9999, 'PLN' );  // 99,99 zł
echo Currency::format_localized( 9999, 'BRL' );  // R$ 99,99

// Override locale if needed
echo Currency::format_localized( 9999, 'EUR', 'en_IE' );  // €99.99
```

Requires the PHP intl extension. Falls back to `format()` if unavailable.

HTML Rendering
--------------

[](#html-rendering)

For admin tables and templates:

```
// Render as HTML span
echo Currency::render( 9999, 'USD' );
// $99.99

echo Currency::render( 9999, 'GBP' );
// £99.99
```

Conversion Methods
------------------

[](#conversion-methods)

```
// Convert decimal to Stripe's smallest unit
$cents  = Currency::to_smallest_unit( 99.99, 'USD' );   // 9999
$yen    = Currency::to_smallest_unit( 9999, 'JPY' );    // 9999 (no decimals)
$dinars = Currency::to_smallest_unit( 9.999, 'KWD' );   // 9999 (three decimals)

// Convert from Stripe's smallest unit to decimal
$dollars = Currency::from_smallest_unit( 9999, 'USD' );  // 99.99
$yen     = Currency::from_smallest_unit( 9999, 'JPY' );  // 9999.0
$dinars  = Currency::from_smallest_unit( 9999, 'KWD' );  // 9.999
```

Currency Information
--------------------

[](#currency-information)

```
// Get currency name
$name = Currency::get_name( 'USD' );  // US Dollar

// Get currency symbol
$symbol = Currency::get_symbol( 'GBP' );  // £

// Get decimal places
$decimals = Currency::get_decimals( 'USD' );  // 2

// Get the native locale for a currency
$locale = Currency::get_native_locale( 'EUR' );  // de_DE

// Get full configuration
$config = Currency::get_config( 'EUR' );
// Returns: ['name' => 'Euro', 'symbol' => '€', 'decimals' => 2, 'locale' => 'de_DE', 'country' => 'EU', 'country_name' => 'Eurozone']

// Get currencies formatted for select dropdowns
$options = Currency::get_options();
// Returns: ['USD' => 'US Dollar ($) — USD', 'EUR' => 'Euro (€) — EUR', ...]

// Check if currency is supported
if ( Currency::is_supported( 'USD' ) ) {
    // Valid Stripe currency
}

// Check if zero-decimal currency
if ( Currency::is_zero_decimal( 'JPY' ) ) {
    // Handle zero-decimal logic
}
```

Country Data
------------

[](#country-data)

Each currency includes its primary country of origin with ISO 3166-1 alpha-2 codes:

```
// Get country code
$country = Currency::get_country( 'GBP' );       // GB
$country = Currency::get_country( 'THB' );       // TH

// Get country name
$name = Currency::get_country_name( 'GBP' );     // United Kingdom
$name = Currency::get_country_name( 'EUR' );     // Eurozone

// Reverse lookup: find currency by country
$currencies = Currency::get_by_country( 'US' );  // ['USD']
$currencies = Currency::get_by_country( 'CH' );  // ['CHF']

// Get dropdown options with country names (Revolut-style)
$options = Currency::get_country_options();
// Returns: ['USD' => 'US Dollar · United States — USD', 'GBP' => 'British Pound · United Kingdom — GBP', ...]
```

Regional currencies use descriptive names: EUR → "Eurozone", XAF → "Central Africa", XOF → "West Africa".

Stripe Integration Example
--------------------------

[](#stripe-integration-example)

```
// Processing a payment
$amount   = 99.99;
$currency = 'USD';

// Convert to Stripe format
$stripe_amount = Currency::to_smallest_unit( $amount, $currency );

// Create Stripe charge
$charge = \Stripe\Charge::create( [
    'amount'   => $stripe_amount,  // 9999 (cents)
    'currency' => strtolower( $currency ),
] );

// Display formatted amount to customer
echo Currency::format_localized( $charge->amount, $currency );
```

Helper Functions
----------------

[](#helper-functions)

Global functions are available for convenience:

```
// Currency data
$name     = get_currency_name( 'USD' );              // US Dollar
$symbol   = get_currency_symbol( 'GBP' );             // £
$decimals = get_currency_decimals( 'USD' );            // 2
$country  = get_currency_country( 'GBP' );             // GB
$cname    = get_currency_country_name( 'GBP' );        // United Kingdom
$codes    = get_currency_by_country( 'US' );            // ['USD']
$options  = get_currency_options();                     // ['USD' => 'US Dollar ($) — USD', ...]
$copts    = get_currency_country_options();             // ['USD' => 'US Dollar · United States — USD', ...]

// Formatting
$price = format_currency( 9999, 'USD' );               // $99.99
$price = format_currency( 9999, 'EUR', 'de_DE' );      // 99,99 €
$plain = format_currency_plain( 9999, 'USD' );          // 99.99
$html  = render_currency( 9999, 'USD' );                // $99.99
esc_currency_e( 9999, 'USD' );                          // Echoes: $99.99

// Unit conversion
$cents   = to_currency_cents( 19.99, 'USD' );           // 1999
$dollars = from_currency_cents( 1999, 'USD' );           // 19.99

// Validation
$supported = is_currency_supported( 'USD' );             // true
$zero_dec  = is_currency_zero_decimal( 'JPY' );          // true
```

Zero-Decimal Currencies
-----------------------

[](#zero-decimal-currencies)

These currencies don't use decimal places: BIF, CLP, DJF, GNF, JPY, KMF, KRW, MGA, PYG, RWF, VND, VUV, XAF, XOF, XPF.

Special Case Currencies
-----------------------

[](#special-case-currencies)

Some currencies have quirks in Stripe's API that this library handles automatically:

- **ISK, UGX** — Logically zero-decimal but Stripe requires two-decimal representation for backward compatibility. Treated as two-decimal in the API.
- **HUF, TWD** — Zero-decimal for payouts only; charges accept two-decimal amounts. Treated as two-decimal in the API.

Three-Decimal Currencies
------------------------

[](#three-decimal-currencies)

These currencies use three decimal places: BHD, JOD, KWD, OMR, TND.

API Reference
-------------

[](#api-reference)

MethodDescriptionReturn**Currency Data**`all()`Get all currencies`array``get_config($currency)`Get currency configuration`?array``get_name($currency)`Get currency name`string``get_symbol($currency)`Get currency symbol`string``get_decimals($currency)`Get decimal places`int``get_native_locale($currency)`Get native locale`string``get_country($currency)`Get ISO country code`string``get_country_name($currency)`Get country name`string``get_by_country($country)`Get currencies for a country`array``get_options()`Get formatted select options`array``get_country_options()`Get options with country names`array``get_codes()`Get code-to-code map`array`**Formatting**`format($amount, $currency)`Format with symbol`string``format_localized($amount, $currency, $locale)`Locale-aware format`string``format_plain($amount, $currency)`Format without symbol`string``format_with_code($amount, $currency)`Format with currency code`string``render($amount, $currency)`Render as HTML span`string`**Unit Conversion**`to_smallest_unit($amount, $currency)`Convert to Stripe units`int``from_smallest_unit($amount, $currency)`Convert from Stripe units`float`**Validation**`is_supported($currency)`Check if supported`bool``is_zero_decimal($currency)`Check if zero-decimal`bool`Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- WordPress 6.0 or higher
- PHP intl extension (optional, for locale-aware formatting)

License
-------

[](#license)

GPL-2.0-or-later

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance52

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (15 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-currencies/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-currencies/health.svg)](https://phpackages.com/packages/arraypress-wp-currencies)
```

###  Alternatives

[rairlie/laravel-locking-session

Provide session locking in Laravel

92486.9k1](/packages/rairlie-laravel-locking-session)[code-tool/jaeger-client-php

35526.6k9](/packages/code-tool-jaeger-client-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
