Skip to main content

Precious Metal Pricing

The MetalPricing class (inc/class-metal-pricing.php) manages the retrieval of spot prices and the calculation of final dealer prices on the Dealers Site.


Spot Price Storage

Spot prices are stored as WordPress options, updated periodically by external syncs:

Option KeyDescription
spot_price_goldCurrent gold spot price (USD/oz)
spot_price_silverCurrent silver spot price (USD/oz)
spot_price_platinumCurrent platinum spot price (USD/oz)
spot_price_modifier_goldDollar adjustment added to/subtracted from gold spot
spot_price_modifier_silverDollar adjustment added to/subtracted from silver spot
spot_price_modifier_platinumDollar adjustment added to/subtracted from platinum spot
markup_modifier_goldAdditional markup modifier for gold
markup_modifier_silverAdditional markup modifier for silver
markup_modifier_platinumAdditional markup modifier for platinum

Markup Modes

ModeFormula
each_fixedfinal_price = spot_price + fixed_markup_per_unit
weight_percentfinal_price = spot_price + (spot_price × markup_rate) per ounce × weight

Public REST API

The GET /suma/v1/spot-prices endpoint (registered by Endpoints\Pricing) exposes current prices publicly:

[
{
"name": "gold",
"price": "1927.40",
"change": "+0.32%",
"changeType": "increase"
},
{
"name": "silver",
"price": "23.18",
"change": "-0.10%",
"changeType": "decrease"
}
]

This endpoint powers the Price Ticker Elementor widget shown site-wide.


Price Import Endpoint

The POST /suma/v1/prices endpoint (registered by Endpoints\Pricing) receives price data from the Middleware Platform's HTTP Sync Target and writes it to WooCommerce product meta. This updates _price, _regular_price, _markup_rate, _markup_mode, _volume_pricing, and _metal_weight on WooCommerce product posts.

The compact payload field map used during import includes:

  • wa -> base ask / regular price
  • mr -> markup rate
  • mm -> markup mode
  • t -> tier pricing JSON
  • w -> metal weight

Authentication uses a shared token defined as PRICES_API_TOKEN in wp-config.php.