getCampaignIdFromCookie(); if (!$cid) { return; } $order = Arr::get($eventData, 'order'); if (!$order || empty($order->id)) { return; } if ($order->getMeta('_fc_cid')) { return; } $order->updateMeta('_fc_cid', $cid); } /** * On payment success, accumulate this order's total into the campaign's * `_campaign_revenue` meta. Helper::recordCampaignRevenue handles dedup * (same order_id won't be counted twice) and per-currency bucketing. */ public function recordRevenue($eventData) { $order = Arr::get($eventData, 'order'); if (!$order || empty($order->id)) { return; } $cid = (int) $order->getMeta('_fc_cid'); if (!$cid) { return; } // FluentCart stores monetary amounts as integer cents — same convention the // Woo re-sync uses when writing into `_campaign_revenue`. $amountCents = (int) $order->total_amount; if ($amountCents <= 0) { return; } $currency = $order->currency ? strtoupper($order->currency) : 'USD'; FluentCrmHelper::recordCampaignRevenue($cid, $amountCents, $order->id, $currency); } private function getCampaignIdFromCookie() { if (empty($_COOKIE['fc_cid'])) { return 0; } $cid = (int) $_COOKIE['fc_cid']; if ($cid <= 0) { return 0; } $exists = Campaign::withoutGlobalScopes()->where('id', $cid)->exists(); return $exists ? $cid : 0; } }