alexgrey
alexgrey

Reputation: 93

How to add added_to_cart trigger correctly?

I added ajax to single product page using that way and it (ajax)works, but I still have no reaction on

jQuery(document).ready(function($){
    $('body').on( 'added_to_cart', function(){
        alert("testing!");
    });
});

I want to make popup visible after adding product to cart. The popup is standard - with options go cart link or stay there and close popup. What can be wrong? No reaction on that trigger at all

Upvotes: 0

Views: 582

Answers (1)

Mr. Jo
Mr. Jo

Reputation: 5261

Try this code:

(function ( $ ) {
    $( document ).ready( function () {
        $( document.body ).on( 'added_to_cart', function () {
            alert( "testing!" );
        } );
    } );
})( jQuery );

I'm using this as well and on my page it works.

If it don't works, be sure your JS script get's loaded by opening the console and check the sources. You can also add an alert to your ready function as well.

Upvotes: 1

Related Questions