Target WooCommerce Products and Pages Using PHP Conditionals
WooCommerce comes with a number of pages and a custom post type named ‘products‘, sometimes you may want to just target some of these products or pages so you can add some PHP custom code in your functions.php file of your theme, this can target all or parts of WooCommerce using PHP conditional statements.
All WooCommerce Pages (but not quite!)
is_woocommerce()
All woocommerce pages including products and categories but not the cart and checkout page
The Cart page
is_cart()
The cart page.
The Checkout page
is_checkout()
The checkout page
Product Pages
is_product() is_single(3837) is_single(array(3837, 3894, 3835))
You can use is_single to target specific products.
First targets all single product pages, second targets specific product ID, third targets and array of Product IDs
Product Category Archive Page
is_product_category() is_product_category('red') is_product_category(array ('red', 'green', 'blue'))
First targets all Prod Cats, second targets specific, third targets an array of Prod Cats.
Product Tag Archive Page
is_product_tag() is_product_tag('red') is_product_tag(array ('red', 'green', 'blue'))
First targets all Prod Tags, second targets specific, third targets an array of ProdTags.
My Account Pages
is_account_page()
WooCommerce Endpoints
is_wc_endpoint_url() is_wc_endpoint_url( 'order-pay' ) is_wc_endpoint_url( 'order-received' ) is_wc_endpoint_url( 'view-order' ) is_wc_endpoint_url( 'edit-account' ) is_wc_endpoint_url( 'edit-address' ) is_wc_endpoint_url( 'lost-password' ) is_wc_endpoint_url( 'customer-logout' ) is_wc_endpoint_url( 'add-payment-method' )