Woocommerce: Best way to insert Javascript in template files

sometimes it is necessary to insert jquery in template files. Instead of just writing the script tag straight away, use woocommerce built-in capability.

Say I want to modify fancybox behaviour in the product page to not display the title upon popup, I add this snippet in the single-product/product-image.php for example.

<?php 
ob_start(); 
?>
jQuery("a.zoom, a.show_review_form").fancybox({
'titleShow' : false,
});
<?php 
$code = ob_get_clean(); 
$woocommerce->add_inline_js($code);
?>

Note that the fancy code example used here is ver 1.3. There are newer version by the time you read this.

Like it.? Share it:

Comments are closed.