Commerce: how can I execute javascript after a product has been added to the cart? I want to run Javscript once a product has been added to cart (with the script including product info).

The only thing I have tried is hook_commerce_cart_product_add() with drupal_add_js() but this doesn't seem to work. Ideally I would like it work like drupal_set_message(), so the script displays on the next page view.

I also need to get this working with removing products from the cart.

EDIT: Well I've discovered that doing the following actually works, but seems dodgy as hell, and would like to find a better way:

drupal_set_message("&lt;script&gt;alert('TEST');&lt;/script&gt;");


Any ideas would be welcomed!
You should better use Rules here and the related events. The hook you mention (hook_commerce_cart_product_add) is a rules event hook.

Commerce Cart: After adding/removing a product to the cart


Then on the action add with php the js (drupal_add_js()) but if you simply want to show a message there is an action to do this easily.

System: Show a message on the site