WooCommerce Sync Target
The WooCommerce sync target pushes nFusion prices directly into a WooCommerce database by updating the WordPress wp_postmeta table. This is the primary sync method for both the Retail and Dealers WooCommerce stores.
How It Works
The provider connects to the WooCommerce database using a dedicated Laravel database connection (separate from the middleware's own database). It:
- Calls the nFusion General API (
api.nfusionsolutions.biz) to fetch the current gold, silver, and platinum spot prices. - Writes the spot prices snapshot to the
wp_optionstable (key:suma_metal_spot_prices). - Looks up each product by SKU (
_skumeta key) to find itspost_id. - Updates
_price,_regular_price, and optionally_sale_price/_sale_price_dates_from/_sale_price_dates_toinwp_postmeta. - Stores
_markup_rate,_markup_mode,_metal_weight, and_volume_pricing(tier data) as additional meta. - Processes products in configurable chunk sizes to avoid memory exhaustion.
Configuration Settings
Configured per sync target in the Filament admin:
| Setting | Default | Description |
|---|---|---|
connection | woocommerce | Laravel DB connection name (set in config/database.php) |
postmeta_table | wp_postmeta | WooCommerce post meta table name |
sku_meta_key | _sku | Meta key used to match SKU |
price_meta_key | _price | Meta key for the active price |
regular_price_meta_key | _regular_price | Meta key for the regular price |
sale_price_meta_key | _sale_price | Meta key for the sale price |
sale_price_dates_from_meta_key | _sale_price_dates_from | Sale start date meta key |
sale_price_dates_to_meta_key | _sale_price_dates_to | Sale end date meta key |
markup_meta_key | _markup_rate | Meta key for the markup rate |
markup_mode_meta_key | _markup_mode | Meta key for the markup mode |
tier_meta_key | _volume_pricing | Meta key for volume pricing tiers (stored as JSON) |
weight_meta_key | _metal_weight | Meta key for the product's metal weight in troy ounces |
spot_options_table | wp_options | WordPress options table to write the spot prices snapshot to |
spot_option_key | suma_metal_spot_prices | Option name under which the JSON spot snapshot is stored |
chunk_size | 500 | Number of SKUs processed per DB batch (50–5000) |
Spot Prices Option
On every sync run, the provider fetches the current gold, silver, and platinum spot prices from the nFusion General API and writes them to a single wp_options row. This allows WooCommerce themes and plugins to read live spot prices via the standard WordPress get_option() function.
$spotPrices = get_option('suma_metal_spot_prices'); // returns decoded array
The stored value is a JSON object:
{
"gold": { "ask": 4550.93, "bid": 4548.93 },
"silver": { "ask": 72.054, "bid": 71.204 },
"platinum": { "ask": 1893.20, "bid": 1883.20 }
}
If the nFusion General API call fails, the wp_options write is skipped silently — a warning is logged but the rest of the product price sync continues normally. The option retains the value from the previous successful sync.
Database Connection Setup
Add the WooCommerce database credentials to .env:
DB_WOOCOMMERCE_HOST=your-woo-db-host
DB_WOOCOMMERCE_PORT=3306
DB_WOOCOMMERCE_DATABASE=woocommerce_db
DB_WOOCOMMERCE_USERNAME=woo_user
DB_WOOCOMMERCE_PASSWORD=secret
Then register the connection in config/database.php:
'woocommerce' => [
'driver' => 'mysql',
'host' => env('DB_WOOCOMMERCE_HOST', '127.0.0.1'),
'port' => env('DB_WOOCOMMERCE_PORT', '3306'),
'database' => env('DB_WOOCOMMERCE_DATABASE', ''),
'username' => env('DB_WOOCOMMERCE_USERNAME', ''),
'password' => env('DB_WOOCOMMERCE_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation'=> 'utf8mb4_unicode_ci',
],
Markup Modes
| Mode | Description |
|---|---|
each_fixed | Fixed dollar markup per unit |
weight_percent | Percentage of the base ask price, multiplied by product weight (in ounces) |
The _markup_mode meta key stores this value for reference by the WooCommerce theme layer.
Volume Pricing Tiers
When tier data is available, the provider stores it as a JSON array in _volume_pricing:
[
{"qty": 1, "ask": 28.50, "markup": 1.50},
{"qty": 10, "ask": 27.00, "markup": 0.00},
{"qty": 25, "ask": 26.00, "markup": -1.00}
]
The Dealers WooCommerce theme reads this meta to display stepped pricing tables.
Tier data is sorted and normalized in via the sortTiersByQuantityAscending() function located in app/Utils/PricingUtils.php file.
As of 5/18/2026, we found and issue when syncing data from the nFusion API. In the nFusion dashboard tier data is always sorted by quantity ascending, but tier data from the API comes through in the order tiers are created. Site logic expects tier data to be stored ascending by quantity.
Key File
app/SyncTargets/WooCommerce/WooCommerceSyncTargetProvider.php