Cyber Week Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] Sidebar only on shop page and underlying pages

Home Forums Support Sidebar only on shop page and underlying pages

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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

    GeneratePress 1.4
    GP Premium 1.4.3
    #379532
    Leo
    Staff
    Customer Support
    #379554
    Eric

    Yes I tried the WooCommerce function from there but that one also enables the sidebar on product pages (which I don’t want).

    #379697
    Leo
    Staff
    Customer Support

    Hmm 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;
    
     }
    #379899
    Eric

    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

    #379944
    Tom
    Lead Developer
    Lead Developer

    What 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.

    #379947
    Eric

    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

    #379950
    Tom
    Lead Developer
    Lead Developer

    Ah, sorry about that. Just updated the code so it should work now.

    #379951
    Eric

    That’s awesome, it worked!

    Thanks

    #380011
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.