Does anyone know how to add JavaScript to all WooCommerce products? From what I've read, I might need to upload the code on my server as a .js and then point to it via a function?

1 Answer 1


If you need to do this on the single product page use this condition then enqueue the JavaScript files.

function enqueue_single_product_javascript()
       // Use wp_enqueue_script()
add_action('wp_enqueue_scripts', 'enqueue_single_product_javascript');

https://developer.wordpress.org/reference/functions/wp_enqueue_script/ https://docs.woocommerce.com/document/conditional-tags/

  • Thanks a lot for the response! Can you please provide a little more detail as I'm getting an fatal error. I am trying: wp_enqueue_script('script', 'urlpath'/chat.js')
    – squidg
    Dec 13, 2016 at 11:10
  • Can you post a copy of the function you're enqueueing your script on? Also, what does the error say? Dec 13, 2016 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.