From e1adde6c5a203fdd54d093eb0ffc6abb3d4c60cc Mon Sep 17 00:00:00 2001 From: Brett Shumaker Date: Wed, 30 Oct 2024 13:58:40 -0400 Subject: [PATCH] Fix single product page view tracks. (#9644) --- changelog/9550-fix-single-product-page-view-tracks | 4 ++++ includes/class-woopay-tracker.php | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelog/9550-fix-single-product-page-view-tracks diff --git a/changelog/9550-fix-single-product-page-view-tracks b/changelog/9550-fix-single-product-page-view-tracks new file mode 100644 index 00000000000..90e5ae60dff --- /dev/null +++ b/changelog/9550-fix-single-product-page-view-tracks @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fixed single product page view tracks when BNPL and PRB payment methods are inactive. diff --git a/includes/class-woopay-tracker.php b/includes/class-woopay-tracker.php index 2da1e544132..78e7ea5c8da 100644 --- a/includes/class-woopay-tracker.php +++ b/includes/class-woopay-tracker.php @@ -622,12 +622,22 @@ public function add_frontend_tracks_scripts() { WC_Payments::register_script_with_dependencies( 'wcpay-frontend-tracks', 'dist/frontend-tracks' ); - wp_enqueue_script( 'wcpay-frontend-tracks' ); + // Define wcpayConfig before the frontend tracks script if it hasn't been defined yet. + $wcpay_config = rawurlencode( wp_json_encode( WC_Payments::get_wc_payments_checkout()->get_payment_fields_js_config() ) ); + wp_add_inline_script( + 'wcpay-frontend-tracks', + " + var wcpayConfig = wcpayConfig || JSON.parse( decodeURIComponent( '" . esc_js( $wcpay_config ) . "' ) ); + ", + 'before' + ); wp_localize_script( 'wcpay-frontend-tracks', 'wcPayFrontendTracks', $frontent_tracks ); + + wp_enqueue_script( 'wcpay-frontend-tracks' ); } }