Use WooCommerce store currency for product and order money.
Deploy Ladill Woo Manager / deploy (push) Successful in 35s
Deploy Ladill Woo Manager / deploy (push) Successful in 35s
Sync currency from the plugin, format product prices and totals with it, and show the store currency on product price fields instead of hard-coding GHS.
This commit is contained in:
@@ -70,4 +70,39 @@ class WooStore extends Model
|
||||
{
|
||||
return rtrim((string) config('app.url'), '/').'/webhooks/woocommerce/'.$this->public_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce store currency (ISO 4217), synced from the connected site.
|
||||
* Does not fall back to GHS — unknown currency is empty until the next sync.
|
||||
*/
|
||||
public function currency(): string
|
||||
{
|
||||
$meta = is_array($this->metadata) ? $this->metadata : [];
|
||||
$currency = strtoupper(trim((string) ($meta['currency'] ?? '')));
|
||||
|
||||
return preg_match('/^[A-Z]{3}$/', $currency) === 1 ? $currency : '';
|
||||
}
|
||||
|
||||
public function currencySymbol(): string
|
||||
{
|
||||
$meta = is_array($this->metadata) ? $this->metadata : [];
|
||||
$symbol = trim((string) ($meta['currency_symbol'] ?? ''));
|
||||
if ($symbol !== '') {
|
||||
return $symbol;
|
||||
}
|
||||
|
||||
return $this->currency();
|
||||
}
|
||||
|
||||
public function formatMoney(int|float|null $minor): string
|
||||
{
|
||||
if ($minor === null) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
$currency = $this->currency();
|
||||
$amount = number_format(((int) $minor) / 100, 2);
|
||||
|
||||
return $currency !== '' ? $currency.' '.$amount : $amount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user