最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - How to distinguish pages created by woocommerce?

programmeradmin1浏览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.

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().

发布评论

评论列表(0)

  1. 暂无评论