0

I would like to display Materialize framework Toast, when the product has been added to cart. The hook for it is woocommerce_ajax_add_to_cart, or at least I think it is from all the google material I have managed to dig up.

My problem is I can not get it to work. What would be the best approach for that, how would I be able to hook into it.

I have this in my functions.php:

add_action('woocommerce_ajax_add_to_cart', 'run_toast_after_add_to_cart');
function run_toast_after_add_to_cart() {
  echo '<a class="btn" onclick="Materialize.toast('I am a toast', 4000)">Toast!</a>';
}

But I get:

Parse error: syntax error, unexpected 'I' (T_STRING), expecting ',' or ';'

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Mareks
  • 135
  • 1
  • 2
  • 12
  • You should show your code so far. Your are more likely yo get help that way. – Filipe Teixeira Jul 08 '16 at 09:44
  • 1
    You should store for example in a variable `$text = 'I am a toast';` before and then you should use it: `echo 'Toast!';` This way you should avoid the error… – LoicTheAztec Jul 08 '16 at 14:55
  • Thank you. I managed to get it work. The variable did the trick. I ended up adding onclick function to my button in add-to-cart.php – Mareks Jul 08 '16 at 16:40

0 Answers0