如何从主题中删除WoodCommerce.css文件? [英] How to remove the woocommerce.css file from the theme?

查看:11
本文介绍了如何从主题中删除WoodCommerce.css文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是WordPress,并且安装了WooCommerce插件。

我在我的主题中添加了模板文件夹,并开始自定义我的主题。

现在,我必须从我的主题中删除Woocommerce.css,我在官方网站here

找到了代码

我在函数中添加了相同的代码。php

add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );

add_filter( 'woocommerce_enqueue_styles', '__return_false' );

但这两个答案都不起作用。我已经安装了5.7.1 WooCommerce。

如何解决此问题?

函数.php

function customtheme_scripts() {
    wp_enqueue_style( 'customtheme-style', get_stylesheet_uri(), array(), time() );
    wp_style_add_data( 'customtheme-style', 'rtl', 'replace' );
    wp_enqueue_script( 'customtheme-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
    wp_dequeue_style( 'customtheme-woocommerce-style' );
}
add_action( 'wp_enqueue_scripts', 'customtheme_scripts' );

查看源代码

域名只是一个例子。

推荐答案

这个答案已经在WooCommerce5.x+上进行了充分的测试,并且在默认的Woo样式表上运行良好!如果您使用的是自定义主题和/或自定义样式表,则可能会遇到一些差异。

您在文档页面上看到的内容不再适用于WOO4+according to their github page

因此您需要将其样式出列!

wp_dequeue_styleDocs

因此,如果您只想删除woocommerce.css文件,则可以执行以下操作:

add_action('wp_enqueue_scripts', 'removing_woo_styles');

function removing_woo_styles()
{
  wp_dequeue_style('woocommerce-general'); // This is "woocommerce.css" file
}

但是,如果您想要删除woo加载的所有样式表,则可以使用以下命令:

add_action('wp_enqueue_scripts', 'removing_woo_styles');

function removing_woo_styles()
{
  wp_dequeue_style('wc-block-vendors-style');
  wp_dequeue_style('wc-block-style');
  wp_dequeue_style('woocommerce-general');
  wp_dequeue_style('woocommerce-layout');
  wp_dequeue_style('woocommerce-smallscreen');
}

如果您仍然可以看到样式,请尝试清除缓存。


与问题&Quot;自定义样式表&Quot;相关的更新

在我写答案的时候,您还没有提供任何样式表的屏幕截图,也没有提到任何关于使用定制样式表的内容。这就是您无法使其工作的原因。

如果您使用的是自定义样式表,请不要复制/粘贴,如问题中使用的自定义css文件。wp_dequeue_style函数将您的样式表句柄作为参数。因此,请先阅读文档。您正在使用自定义句柄名称(即Customheme-WooCommerce-Style&Quot;),因此,您需要使用该句柄名称。

add_action('wp_enqueue_scripts', 'removing_woo_styles');

function removing_woo_styles()
{
  wp_dequeue_style('customtheme-woocommerce-style'); // This is your "custom style sheet" file.
}
还请注意,注释掉主文件中的入队部分(即inc/woocommerce.php)可能会暂时起作用,但在下一次WOO更新时,它会再次出现。因此,建议您尽量避免更新模板文件,除非您真的必须这样做,而这里不是这种情况!

这篇关于如何从主题中删除WoodCommerce.css文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆