'flowfy_aid', 'fbc' => '_fbc', 'fbp' => '_fbp', 'ttclid' => 'ttclid', 'ttp' => '_ttp', 'scclid' => '_scclid', 'gclid' => '_gcl_aw', ); public static function register(): void { add_action( 'woocommerce_checkout_create_order', array( self::class, 'on_classic_checkout' ) ); add_action( 'woocommerce_store_api_checkout_update_order_from_request', array( self::class, 'on_store_api_checkout' ) ); } public static function on_classic_checkout( $order ): void { if ( $order instanceof WC_Order && Connection::is_active() ) { $order->update_meta_data( self::META, self::build() ); } } public static function on_store_api_checkout( $order ): void { if ( $order instanceof WC_Order && Connection::is_active() ) { $order->update_meta_data( self::META, self::build() ); if ( $order->get_id() ) { $order->save_meta_data(); } } } public static function build(): array { $context = array( 'ip' => (string) WC_Geolocation::get_ip_address(), 'user_agent' => self::cap( (string) wc_get_user_agent() ), ); foreach ( self::COOKIES as $key => $cookie ) { $context[ $key ] = self::cookie( $cookie ); } $context['gclid'] = self::gclid( $context['gclid'] ); return array_filter( $context, 'strlen' ); } public static function gclid( string $cookie ): string { $parts = explode( '.', $cookie, 3 ); return 3 === count( $parts ) ? $parts[2] : ''; } private static function cookie( string $name ): string { if ( ! isset( $_COOKIE[ $name ] ) || ! is_string( $_COOKIE[ $name ] ) ) { return ''; } return self::cap( sanitize_text_field( wp_unslash( $_COOKIE[ $name ] ) ) ); } private static function cap( string $value ): string { return substr( $value, 0, self::MAX_LENGTH ); } }