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
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/
-
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')
– squidgDec 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