How do I target on woo-commerce single product page when adding a script I've created only for that particular page?
1 Answer
You can use is_product()
WooCommerce conditional tag to identify if its single product page. Below is example code which enqueues test.js if its a single product page. You may use and tweak this code snippet further.
function mytheme_scripts() {
if ( is_product() ) {
wp_enqueue_script( 'test-js', get_template_directory_uri() . '/js/test.js', array() );
}
}
add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );
is_singlular('product')
would do that or use particular page id.