php - Finding the Page-ID of my Woocommerce Main Shop Page
Get the solution ↓↓↓I am looking to set styling specific to my Woocommerce Main Shop Page. Right now when I try to make css changes to the shop layout, they take place on all pages. I have researched and found that I can use method such as the follow:
<?php
$myaccount_page_id = wc_get_page_id( 'myaccount' );
$shop_page_id = wc_get_page_id( 'shop' );
$cart_page_id = wc_get_page_id( 'cart' );
$checkout_page_id = wc_get_page_id( 'checkout' );
$terms_page_id = wc_get_page_id( 'terms' );
?>
Is this accurate? Do you have a better suggestion? Where do I run this php if this is the best option?
Answer
Solution:
You can add a CSS body class to your main shop page via thebody_class
filter:
add_filter( 'body_class', 'add_body_class_to_main_shop_page', 10, 1 );
function add_body_class_to_main_shop_page( $classes ) {
if ( is_shop() ) $classes[] = 'shop-page';
return $classes;
}
The example above will add the CSS classshop-page
. You can then base your other CSS on that.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.