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.
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.
Share Improve this question asked May 11, 2019 at 15:30 mtbnomtbno 1011 bronze badge 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. – LoicTheAztec Commented May 11, 2019 at 20:51
1 Answer
Reset to default 0You 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()
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745502235a4630469.html
评论列表(0条)