0

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

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

1 Answer 1

0

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 and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.