Trying to run Javascript on AJAX call

Going by your method I would suggest hooking into wp_footer as well, so that your script would be near the end of the body, that way it will be loaded after all DOM was loaded. add_action(‘woocommerce_ajax_added_to_cart’, ‘set_button_classes’); function set_button_classes () { add_action(‘wp_footer’, function () { echo “<script>document.getElementByClassName(‘added_to_cart wc-forward’).classList.add(‘ct-cart-item’, ‘ct-offcanvas-trigger’);</script>”; }); } You could also close … Read more