- This topic has 9 replies, 3 voices, and was last updated 6 years, 2 months ago by
Tom.
-
AuthorPosts
-
September 5, 2017 at 12:59 am #379309
Eric
Hi,
I would like to have a sidebar only on the shop page and all underlying pages. I used this code below but it only applies to the shop page itself, while I also like it to apply to eliv.com.tw/shop/etc (but not all WooCommerce pages like eliv.com.tw/product/etc.). Do you know how this code has to be adjusted to make it work?
add_filter( ‘generate_sidebar_layout’,’tu_custom_woocommerce_sidebar_layout’ );
function tu_custom_woocommerce_sidebar_layout( $layout )
{
$shoppage = “/shop/”;
$currentpage = $_SERVER[‘REQUEST_URI’];
// If we are on a woocommerce page, set the sidebar
if($currentpage == $shoppage) return ‘right-sidebar’;
// Or else, set the regular layout
return $layout;
}Best regards,
Florian
September 5, 2017 at 8:01 am #379532Leo
StaffCustomer SupportHi there,
Can you try the first function here? https://docs.generatepress.com/article/sidebar-layout/#using-a-function
September 5, 2017 at 8:18 am #379554Eric
Yes I tried the WooCommerce function from there but that one also enables the sidebar on product pages (which I don’t want).
September 5, 2017 at 11:32 am #379697Leo
StaffCustomer SupportHmm try this:
add_filter( 'generate_sidebar_layout','tu_custom_woocommerce_sidebar_layout' ); function tu_custom_woocommerce_sidebar_layout( $layout ) { // If we are on a woocommerce page, set the sidebar if ( function_exists( 'is_woocommerce' ) && is_woocommerce() && !is_shop() ) return 'both-left'; // Or else, set the regular layout return $layout; }
September 5, 2017 at 7:29 pm #379899Eric
Hi Leo,
Thanks for your reply, however, this doesn’t work and doesn’t return a sidebar (also when I replace both-left with right-sidebar).
Best regards,
Florian
September 5, 2017 at 10:38 pm #379944Tom
Lead DeveloperLead DeveloperWhat about this?:
add_filter( 'generate_sidebar_layout','tu_custom_woocommerce_sidebar_layout' ); function tu_custom_woocommerce_sidebar_layout( $layout ) { // If we are on a woocommerce page, set the sidebar if ( function_exists( 'is_woocommerce' ) && is_woocommerce() && ! is_singular( 'product' ) ) return 'right-sidebar'; // Or else, set the regular layout return $layout; }
That will set the right sidebar to any WC related page, other than single products.
Otherwise, it will use the Customizer setting.
September 5, 2017 at 10:47 pm #379947Eric
Hi Tom,
When I put this code in functions.php replacing the old one, it simply gives a completely white page on all WooCommerce pages.
Best regards,
Florian
September 5, 2017 at 10:57 pm #379950Tom
Lead DeveloperLead DeveloperAh, sorry about that. Just updated the code so it should work now.
September 5, 2017 at 11:00 pm #379951Eric
That’s awesome, it worked!
Thanks
September 6, 2017 at 12:03 am #380011Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.