- What is_product() Checks
- Syntax and Return Value
- When to Call is_product()
- Example 1: Remove Related Products on Single Pages Only
- Example 2: Load a Product Gallery Script
- Common Mistakes
- Related WooCommerce Conditional Tags
- FAQs About is_product()
- Does is_product() return true for variable products?
- Does is_product() return true on the shop page?
- Can I use is_product() in functions.php?
- Is is_product() the same as is_singular( ‘product’ )?
- Conclusion
A single product page is where a buyer makes a decision. Store owners often want to change that page alone, such as removing a section, loading a gallery script, or adding a tracking tag, without touching category pages or the cart.
The woocommerce is_product function, written as is_product(), returns true when the current request is a single product page. This guide explains what it matches, how timing affects it, and two examples you can use.
What is_product() Checks
is_product() is a WooCommerce conditional tag. It returns true when the request shows one product. That includes simple, variable, grouped, and external products, because they all use the same single product page.
The function returns false on the shop page, on category and tag archives, and on the cart and checkout. For the shop, see is_shop().
Syntax and Return Value
- Arguments: none.
- Return value:
trueon a single product page, otherwisefalse. - Where to use it: inside hooks that run after the main query is set up.
When to Call is_product()
Like the other conditional tags, is_product() depends on the main query. Calling it in init or at file load returns false even on a product page.
Use one of these hooks:
- wp fires after the main query is ready, so every conditional tag works.
- wp_enqueue_scripts fires while the page head is built, which suits assets.
- template_redirect fires before the template loads, which suits rules that redirect.
Tip: Many product hooks, such as
woocommerce_single_product_summary, already fire only on single product pages. Check the hook’s purpose first. If it already limits the output to single products, an extra is_product() check adds nothing.
Example 1: Remove Related Products on Single Pages Only
Related products add a long section below the summary. Removing them is a common request, and the removal must stay on single product pages. This example removes the section inside a wp callback that checks is_product() first.
<?php
add_action( 'wp', 'my_product_remove_related' );
function my_product_remove_related() {
if ( ! is_product() ) {
return;
}
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
}The priority 20 matches WooCommerce’s default for the related products output. For a full walkthrough of this change, see the guide on hiding related products in WooCommerce.
Example 2: Load a Product Gallery Script
A product gallery script should load only where the gallery appears. This example enqueues a file on single product pages and nowhere else. Replace the path with your own file.
<?php
add_action( 'wp_enqueue_scripts', 'my_enqueue_product_gallery' );
function my_enqueue_product_gallery() {
if ( ! is_product() ) {
return;
}
wp_enqueue_script(
'my-product-gallery',
get_stylesheet_directory_uri() . '/js/product-gallery.js',
array( 'jquery' ),
'1.0.0',
true
);
}Place the code in a child theme’s functions.php file or in a small site plugin, so it survives theme updates.
Common Mistakes
- Expecting it on archives. Category, tag, and shop pages return false. Use the archive checks for those pages.
- Calling it too early. A check in
initor at file load returns false. Move the call into a hook that runs afterwp. - Checking the title or slug. A product name can change, so compare with the function instead of the title.
- Adding redundant checks. A hook that already fires only on single products does not need an is_product() check.
Related WooCommerce Conditional Tags
Product rules often sit next to the product hooks. If you want to add content above the product, read the guide on the before single product hook. For the summary area, see the single product summary hook. The other page checks are covered in the guides on is_cart(), is_checkout(), is_shop(), and is_account_page().
FAQs About is_product()
Does is_product() return true for variable products?
Yes. Variable products use the same single product page, so the function returns true for them.
Does is_product() return true on the shop page?
No. The shop page and the product archive are separate requests. Use is_shop() for those.
Can I use is_product() in functions.php?
You can call it inside a hook that runs after the main query is ready, such as wp or wp_enqueue_scripts. A direct call at file load returns false.
Is is_product() the same as is_singular( ‘product’ )?
They check the same thing. is_product() is the WooCommerce name and reads more clearly in store code, so use it in WooCommerce projects.
Conclusion
is_product() is the right check for a single product page. Use it inside wp or wp_enqueue_scripts, and skip it when the hook already limits its output to single products.
If you want product pages changed or extended for your store, hire a WooCommerce developer or send your requirements through the application form.
