• Resolved engineerized

    (@engineerized)


    Add to cart ajax filter event not working when product added to cart. Using latest plugin version 1.11.1

    We are using ajax for add to cart.

    Our add to cart button html looks like this:

    <button type="submit" name="add-to-cart" value="123" class="nm-simple-add-to-cart-button single_add_to_cart_button button alt">Add to bag</button>

    When switching off ajax add to cart event pixel is firing but not with ajax enabled.

    It was working on plugin version 1.9.15

    Hope you guys fix this issue on the next update if someone else doesn’t have any other solution for how to solve this?

    • This topic was modified 4 years, 10 months ago by engineerized.
    • This topic was modified 4 years, 10 months ago by engineerized.
Viewing 5 replies - 16 through 20 (of 20 total)
  • Hey @fabiograsso,

    Thanks for sticking with us while you could! I hope that the Tag Manager plugin is a suitable workaround for you in the meantime. Our developers are working on the new version of the plugin with the new authentication API at the moment. My understanding is the server to server functionality would then be possible, which would be implemented further down the line. Thanks so much for giving us another try when it becomes available!

    @engineerized thanks for coming back with their response. If they have not modified the actions in any way, and are using the default WooCommerce ones, then I’m not quite sure why the tracking wouldn’t be working. The plugin is hooked into the woocommerce_ajax_added_to_cart action, which then adds the tracking script to the cart fragments when not redirecting to cart page. If Savoy aren’t overriding this behavior, and it works with a default theme in place like in @fabiograsso’s case, then this seems very strange!

    Really the only way for us to progress here would be to get access to your site directly. We can then add extra debug logging to the woocommerce_ajax_added_to_cart action to see when it is triggered, and also see what the cart fragments are during the process. Being able to view the full Savoy theme files would also be helpful to see what we can suggest.

    To do this, we would need access to your admin dashboard to add the debug logging, and to receive these credentials we would need to speak privately.

    Would it be possible to raise a support request to us directly so that we can look into this further for you?

    Cheers,

    Simon.

    Thread Starter engineerized

    (@engineerized)

    Hi, thank you @skyverge. I was now able to make it work by adding js to listen for wc-ajax and then added following code to the plugin:

    		 /*Use js for add to cart when form is simply submitted via Ajax instead of a page load*/
    		public function add_to_cart_event_js() {
    
    			if ( self::$isEnabled ) {
    	
    			ob_start();
    
    			echo '<script>';
    
    			echo $this->pixel->build_event('AddToCart', [
    					'content_ids'  => $this->get_cart_content_ids(),
    					'content_type' => 'product',
    					'contents'     => $this->get_cart_contents(),
    					'value'        => $this->get_cart_total(),
    					'currency'     => get_woocommerce_currency(),
    				] );
    			echo '</script>';
    			}
    			$pixel = ob_get_clean();
    
    			wp_send_json( $pixel );
    		}

    Hey @engineerized!

    That’s awesome, thanks so much for sharing. In case it proves helpful to other merchants, could you let me know how you are listening for the wc-ajax trigger?

    I’m still not sure why this wouldn’t be picked up by the plugin at the moment if the default WooCommerce actions are called, though I am glad you’ve found a workaround in the meantime.

    If you would still like us to look into it further to see what we can find, then please do reach out to us directly.

    Thanks again for sharing though!

    Cheers,

    Simon.

    Thread Starter engineerized

    (@engineerized)

    Hey @skyverge. Of course, I was really eager to figure it out and didn’t give up til it worked. Yes for sure, I reused the code from plugin version 1.9.15.

    <script>
    				document.addEventListener('DOMContentLoaded', function() {
    				  jQuery && jQuery(function($){
    					$('body').on('added_to_cart', function(event) {
    					  // Ajax action.
    					  $.get('?wc-ajax=fb_inject_add_to_cart_event', function(data) {
    						$('head').append(data);
    					  });
    					});
    				  });
    				}, false);
    			</script>

    Here is the add_action function that needs to be added to make it all work.

    // AddToCart form is simply submitted via Ajax
    add_action( 'wc_ajax_fb_inject_add_to_cart_event', [ $this, 'add_to_cart_event_js' ] );

    Hey @engineerized,

    Great! Thanks so much for sharing the full workaround. I hope it proves useful to others who might be hitting the same issue.

    If you would like us to take a look at the Savoy theme more closely in the future, then don’t hesitate to reach out!

    Cheers,

    Simon.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Add to cart ajax filter event not working’ is closed to new replies.