posts - How to distinguish pages created by woocommerce?

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 Wooc

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
Add a comment  | 

1 Answer 1

Reset to default 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().

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745502235a4630469.html

相关推荐

  • posts - How to distinguish pages created by woocommerce?

    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 Wooc

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信