在woocommerce裡的 Sidebar ,看部份的免費佈景主題是沒辦法控制他開關的。

因為特別需要,然而用了Generatepress的佈景主題,剛好文件上有寫到

那就手動把它關掉。

使用Code Snippets套件。新增加 以下程式碼 在WooCommerce相關畫面時關閉Sidebar

add_filter( 'generate_sidebar_layout', function( $layout ) {
    // If we are on a woocommerce page, set the sidebar
    if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
        return 'no-sidebar';
    }

    // Or else, set the regular layout
    return $layout;
 } );

You can use any of the available WordPress conditionals to determine your sidebar layout.

These are the available IDs you can return:

left-sidebar
right-sidebar
no-sidebar
both-sidebars
both-left
both-right

Learn how to add PHP here.

Product 頁面 原始畫面因為免費佈景主題關系,無法直接關閉側邊欄選項。除非使用付費主題 間接方式使用Code Snippets套件。新增加 以下程式碼 在WooCommerce相關畫面時關閉 code snippets 安裝 並增加以下code ,將其餘頁面 的 sidebar 關閉

Adding PHP – Documentation

Code Snippets

最後是加上了下面的內容。把產品頁面、購物車頁面、結帳畫面都把側邊欄關掉先

add_filter( 'generate_sidebar_layout', function( $layout ) {
    // If we are on a woocommerce page, set the sidebar
    if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
        return 'no-sidebar';
    }
    if ( function_exists( 'is_cart' ) && is_cart() ) {
        return 'no-sidebar';
    }
	if ( function_exists( 'is_checkout' ) && is_checkout() ) {
        return 'no-sidebar';
    }
    // Or else, set the regular layout
    return $layout;
 } );

Hits: 28