0

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

2

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

function enqueue_single_product_javascript()
{
    if(is_product())
    {
       // 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/

2
  • 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, privacy policy and cookie policy

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