WooCommerce - 如何删除侧边栏

问题描述 投票:0回答:10

我需要删除我的 woocommerce 商店的侧边栏。 我尝试过在选项主题和每个类别中使用后端,但没有结果。

我也尝试过:

1.文件 wp-template-hooks.php 删除--> do_action(..

2.文件archive-product.php 删除--> do_action(..

  1. 插入主题目录中的文件 function.php 和 woocommerce 目录中的 function.php 删除_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );

  2. 数据库中有 2 个表,其中 2 个字段已序列化,但更改此操作存在风险。

无果。

我完成了想法。 侧边栏的可见性保存在数据库中的哪里?还是变量?

你能帮我吗?

谢谢 艾尔啤酒

woocommerce sidebar
10个回答
11
投票

我只是想更新 WooCommerce 版本 3.2.3 - 2017 的这篇文章

好的,WooCommerce 插件包含一个包含所有模板文件的文件夹,如果您想更改自定义主题或子主题上的模板,您需要将所有所需模板复制到根主题文件夹中名为 woocommerce 的文件夹中。这将覆盖插件模板,并允许 WooCommerce 更新覆盖您的自定义更改。这些模板在注释中包含所有 do_actions 和钩子,因此可以轻松理解其工作原理。

也就是说,WooCommerce 有允许您添加或删除代码块的钩子,您可以在此处查看 API 文档

要删除侧边栏,您需要将其添加到主题设置功能中的functions.php文件中

remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );

更新: 您还可以通过从页面编辑器更改页面模板来删除我的帐户和购物车页面上的侧栏。

选择一个没有侧边栏的模板或为主题创建一个新模板并使用

<?php get_sidebar(); ?>
删除该行 希望这有帮助。


8
投票

请将此代码添加到您的functions.php中

function mb_remove_sidebar() {
    return false;
}

add_filter( 'is_active_sidebar', 'mb_remove_sidebar', 10, 2 );

2
投票

将以下行添加到functions.php:

add_action( 'init', function () {
    remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
} );

1
投票

您已经将 WooCommerce 集成到您的主题中了吗?

如果没有,请尝试执行以下三个步骤来在您的主题中集成 WooCommerce。

之后,从

your_theme/woocommerce.php 中删除 get_sidebar();

对我来说效果很好。截图

这里.

希望有帮助。


1
投票
进一步@maksim-borodov 的回答,我想有条件地隐藏侧边栏,即仅在产品页面上。方法如下:

function remove_wc_sidebar_conditional( $array ) { // Hide sidebar on product pages by returning false if ( is_product() ) return false; // Otherwise, return the original array parameter to keep the sidebar return $array; } add_filter( 'is_active_sidebar', 'remove_wc_sidebar_conditional', 10, 2 );

将以下行添加到functions.php:

1
投票
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);

一个特殊情况:DIVI 主题有侧边栏设置,包括 WooCommerce,位于主题选项 > 常规

1
投票

我正在使用GeneratePress(免费版),所以其他解决方案对我不起作用。

0
投票
此页面给了我答案:

https://docs.generatepress.com/article/sidebar-layout/#sidebar-filter

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; } );

这可以通过 woocommerce 侧边栏插件来完成。如果你想通过代码删除,请将此代码添加到functions.php中,

-3
投票
if (!class_exists( 'WooCommerce' ) ) {return;} if(is_cart() || is_checkout() || is_product() || is_shop() || is_account_page()){ ?> <style type="text/css"> #secondary { display: none; } #primary { width:100%; } </style> <?php } }

这里是

-4
投票
:-

转到 wp-content/plugins/woocommerce

在文件single-product.php

中删除以下代码-

<?php /** * woocommerce_sidebar hook * * @hooked woocommerce_get_sidebar - 10 */ do_action('woocommerce_sidebar'); ?>

接下来编辑文件
archive-product.php
并删除以下代码-

<?php /** * woocommerce_sidebar hook * * @hooked woocommerce_get_sidebar - 10 */ do_action('woocommerce_sidebar'); ?>

(提示*在删除此内容之前,请将此页面的整个代码复制并粘贴到硬盘上的单独文本文件中...这样,如果出现任何问题,您可以随时将原始代码粘贴回此文件夹中)

© www.soinside.com 2019 - 2024. All rights reserved.