0

I am working on a theme and I have come to a situation when I need to distinguish the pages that are created by the Woocommerce plugin (e.g Shop, Cart, etc.).

So far I've installed this plugin which adds tags and categories to pages and categorized each Woocommerce page as woocommerce.

Is there a better way to do this? Thanks.

1
  • All pages related to woocommerce have as body tag "woocommerce" (in front end) and some other related body tags too (that are useful for CSS and javascript). For PHP, Themers (or plugin developers) use the dedicated WooCommerce conditional tags that will allow you to target any desired WooCommerce page or end points too. Commented May 11, 2019 at 20:51

1 Answer 1

0

You can use conditional tags or function wc_get_page_id('page_name'), where page_name can be: 'myaccount', 'shop', 'cart', 'checkout', etc.

For example:
Using is_cart() you can check whether the current page is a cart page.
Using wc_get_page_id( 'cart' ); you will receive ID of cart page.

Which way is more suitable for your code you have to decide for yourself. Some conditional tags ( like is_checkout(), is_cart() ) are based on wc_get_page_id().

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.