0

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

alexgrey
  • 93
  • 2
  • 8

1 Answers1

1

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.

Mr. Jo
  • 4,946
  • 6
  • 41
  • 100
  • It doesn't work. But one person advised me the place in a code by my link where I should past my function, and it started to work. Also it has a conflict with that great code(nfortunately) https://stackoverflow.com/questions/36219833/woocommerce-variations-as-radio-buttons – alexgrey May 03 '21 at 13:14
  • In this case there must be something strange going on in your js. If you paste the full js, I can find the error. – Mr. Jo May 03 '21 at 13:37