diff --git a/facebook-commerce-events-tracker.php b/facebook-commerce-events-tracker.php index 951b51311..2ac07085f 100644 --- a/facebook-commerce-events-tracker.php +++ b/facebook-commerce-events-tracker.php @@ -1040,13 +1040,33 @@ public function inject_purchase_event( $order_id ) { 'content_name' => wp_json_encode( $product_names ), 'contents' => wp_json_encode( $contents ), 'content_type' => $content_type, + // Use the actual transaction currency stored on the order 'value' => $order->get_total(), - 'currency' => get_woocommerce_currency(), + 'currency' => $order->get_currency(), 'order_id' => $order_id, ), 'user_data' => $this->get_user_data_from_billing_address( $order ), ); + /** + * Allow last-mile override of the currency used for events. + * + * @param string $currency + * @param string $event_name + * @param \WC_Order|null $order + */ + $event_data['custom_data']['currency'] = apply_filters( + 'facebook_for_woocommerce_event_currency', + $event_data['custom_data']['currency'], + $event_name, + $order + ); + + // (Optional) Normalize value to numeric for robustness + if ( isset( $event_data['custom_data']['value'] ) ) { + $event_data['custom_data']['value'] = (float) $event_data['custom_data']['value']; + } + $event = new Event( $event_data ); $this->send_api_event( $event ); @@ -1085,11 +1105,20 @@ public function inject_subscribe_event( $order_id ) { 'custom_data' => array( 'sign_up_fee' => $subscription->get_sign_up_fee(), 'value' => $subscription->get_total(), - 'currency' => get_woocommerce_currency(), + // Use subscription/order currency, not store default + 'currency' => ( method_exists( $subscription, 'get_currency' ) ? $subscription->get_currency() : get_woocommerce_currency() ), ), 'user_data' => $this->pixel->get_user_info(), ); + // Same currency override hook for Subscribe + $event_data['custom_data']['currency'] = apply_filters( + 'facebook_for_woocommerce_event_currency', + $event_data['custom_data']['currency'], + $event_name, + null + ); + $event = new Event( $event_data ); $this->send_api_event( $event ); @@ -1129,6 +1158,15 @@ public function inject_lead_event() { protected function send_api_event( Event $event, bool $send_now = true ) { $this->tracked_events[] = $event; + /** + * Filter the Event payload before sending to Meta. + * This allows integrators to adjust custom_data (currency/value/contents) per event + * without forking the plugin. + * + * @param Event $event + */ + $event = apply_filters( 'facebook_for_woocommerce_before_send_api_event', $event ); + if ( $send_now ) { try { facebook_for_woocommerce()->get_api()->send_pixel_events( facebook_for_woocommerce()->get_integration()->get_facebook_pixel_id(), array( $event ) );