Skip to content
Advertisement

Javascript and WordPress Uncaught SyntaxError using wp_enqueue_script on single product page of woocommerce

I’m no good at javascript but I think this code is right because it is just copy and paste from Zopim website and it was working before I tried to use their widget in a different approach.

functions.php

JavaScript

I am having another issue with the code above. I can’t get the script file to load on products page. It only work if I remove the if conditional.

zopim.js

JavaScript

This script give me this error:

“Uncaught SyntaxError: expected expression, got ‘<‘” and I have no idea why.

Advertisement

Answer

“It only work if I remove the if conditional.”

  1. I’d write the if statement inside the wp_enqueue_scripts hook. Like so:
JavaScript

“This script give me this error “Uncaught SyntaxError: expected expression, got ‘<‘” and I have no idea why.”

  1. You don’t need script tags in your javascript file. So you could go ahead and remove <script type="text/javascript"> and </script>.

Let me know if you could get it to work.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement