How do I target on woo-commerce single product page when adding a script I've created only for that particular page?

  • is_singlular('product') would do that or use particular page id. – bravokeyl Sep 3 '16 at 9:24

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' );

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.