• Hi,

    The plug-in inserts a localize script for tracking a started checkout. However the implementation does not work.

    In the file includes/wck-cart-functions.php on line 265 wck_insert_checkout_tracking function is creating a localize script through the woocommerce_after_checkout_form action, this results into nothing, because the script it localizes (wck_started_checkout) is not registered here.

    I would suggest the following changes, which made it work for me:

    
    // Remove this hook add_action( 'woocommerce_after_checkout_form', 'wck_insert_checkout_tracking' );
    
    function load_started_checkout() {
        $token = get_option('klaviyo_settings')['public_api_key'];
    
        if ( is_checkout() ) {
            wp_enqueue_script( 'wck_started_checkout', plugins_url( '/js/wck-started-checkout.js', __FILE__ ), null, null, true );
            wp_localize_script( 'wck_started_checkout', 'public_key', array( 'token' => $token ));
            // Like the above line it should localize it here
            wck_insert_checkout_tracking();
        }
    }
    
    // $checkout variable is not used, so it can be removed as parameter
    function wck_insert_checkout_tracking($checkout) {
    
      global $current_user;
      wp_reset_query(); // Side question: Why is this here? And if it is needed why  is the main query not restored at the end of this function?
    
      ...function logic...
    
      // Pass Started Checkout event data to javascript attaching to 'wck_started_checkout' handle
      wp_localize_script( 'wck_started_checkout', 'kl_checkout', $started_checkout_data );
    }
    
  • The topic ‘Tracking code code for tracking started checkout not inserted’ is closed to new replies.