Tracking event error in Algolia

  • salman
    Participant
    8 months, 2 weeks ago #45800

    Yes, there is a fine ajax-add-to-cart.js in which logic has been adjusted.

    Also, now I am getting this error on page reload: wp_localize_script_autocomplete is not defined, and autocomplete is not working anymore.

    Please suggest solutions accordingly.

    wpsolr
    Keymaster
    8 months, 2 weeks ago #45801

    Also, now I am getting this error on page reload: wp_localize_script_autocomplete is not defined, and autocomplete is not working anymore.

    Which page is it?

    salman
    Participant
    8 months, 2 weeks ago #45804

    I’ve got it working now, although I’m not sure why that error was appearing before.

    salman
    Participant
    8 months, 2 weeks ago #45808

    The error (wp_localize_script_autocomplete is not defined) is now resolved after excluding all of wpsolr from wprocket.

    salman
    Participant
    8 months, 2 weeks ago #45810

    Let’s talk about the adding_to_cart event. We have an ajax-add-to-cart.js file in which a jQuery function and logic are performed on our add-to-cart button, with a post-call to add the product to the cart.

    Please provide the solution accordingly so the object ID can also be sent to the add-to-cart event.

    wpsolr
    Keymaster
    8 months, 2 weeks ago #45812

    Working now on our JS scripts to trigger an event that lets you extract the object ID from the cart data, according to your theme’s data structures.

    The script will enable anyone to adapt the default add-to-cart behaviour to their own environment (plugin or theme).

    Testing it right now.

    wpsolr
    Keymaster
    8 months, 2 weeks ago #45813

    Here is the new release: https://www.dropbox.com/s/evviw9zo2ygpn4c/wpsolr-enterprise.23.9-new-custom-add-to-cart-js-events.zip?dl=1

    As shown in the js code below, it now can call your own code that will unpack the objectid and quantity stored in the parameter “data” produced by your theme into the expected parameter object “event_data”. You can start by using console.log(data) to understand how this parameter is made.
    You’ll just need to enqueue your JS code file in your child theme functions.php.

    jQuery(document).ready(function ($) {
        /*
         * Custom js events that can perform some transformations on event_data,
         * if cart data structure was modified by plugin or theme.
         * Must update event_data like {product_id: '123', quantity: 1}
         */
    
        // Add to cart button with Ajax on shop or product search page
        $(document).on('wpsolr_on_adding_to_cart_event', function (e, data, event_data) {
            event_data.product_id = (extract from parameter "data");
            event_data.quantity = (extract from parameter "data");
        });
    
        // Add to cart button on product page with form submit and page reload
        $(document).on('wpsolr_on_added_to_cart_event', function (e, data, event_data) {
            event_data.product_id = (extract from parameter "data");
            event_data.quantity = (extract from parameter "data");
        });
    });
    salman
    Participant
    8 months, 2 weeks ago #45814

    Thank you, I will be testing and will let you know.

    salman
    Participant
    8 months, 2 weeks ago #45816

    I tried it out, but we don’t have a child theme. I placed it in our main functions.php file, but I didn’t see any console in either of these functions.

    I added your code to the custom.js file and used it like this in the main funtions.php file, which is placed in the root folder directory.

    function enqueue_custom_script() {
    wp_enqueue_script( ‘custom-js’, get_template_directory_uri() . ‘/js/custom.js’, array(‘jquery’), null, true );
    }
    add_action( ‘wp_enqueue_scripts’, ‘enqueue_custom_script’ );

    salman
    Participant
    8 months, 2 weeks ago #45817

    It’s working now. There was a mistake on my end. My bad.
    Thank you!

Viewing 10 posts - 16 through 25 (of 25 total)

You must be logged in to reply to this topic.