Add javascript to a woocommerce page template

I have the following code in my functions.php

add_action( 'wp_enqueue_scripts', 'dc_datepicker_options' );

function dc_datepicker_options() {
if ( is_page_template( 'single-product.php' ) ) {
  $ss_url = get_stylesheet_directory_uri();
  wp_enqueue_script( 'datepicker-options', "{$ss_url}/js/datepicker-options.js" );
} else {
    // Returns false 
}
}

I’m trying to call datepicker-options.js only on my product pages. But it doesn’t seem to be calling it.

1 Answer
1

There is Woocommerce conditional tag for single product page

Try

if(is_product())

instead of

if ( is_page_template( 'single-product.php' ))

Leave a Comment