Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何删除添加到Woocommerce.product的类?_Php_Wordpress_Woocommerce_Taxonomy Terms - Fatal编程技术网

Php 如何删除添加到Woocommerce.product的类?

Php 如何删除添加到Woocommerce.product的类?,php,wordpress,woocommerce,taxonomy-terms,Php,Wordpress,Woocommerce,Taxonomy Terms,Woocommerce将指定的产品类别和属性作为自定义类添加到li.product <li class="post-120 product type-product status-publish has-post-thumbnail category1 category2 category3 category4 pa_one pa_two..."> 我们为每个产品分配了相当多的类别,这降低了网站的速度。有没有办法删除这些附加类?如果您了解php,可以编辑Woocommerce

Woocommerce将指定的产品类别和属性作为自定义类添加到li.product

<li class="post-120 product type-product status-publish has-post-thumbnail 
category1 category2 category3 category4 pa_one pa_two...">

  • 我们为每个产品分配了相当多的类别,这降低了网站的速度。有没有办法删除这些附加类?

    如果您了解php,可以编辑Woocommerce php模板文件来删除这些附加类。
    如果打开该文件,将添加一个php变量作为附加类,它是一个数组。

    如果您了解php,可以编辑Woocommerce php模板文件以删除这些附加类。
    如果打开该文件,将添加一个php变量作为附加类,它是一个数组。

    我建议对post_类函数应用一个过滤器,而不是编辑模板,因为woocommerce会定期更新这些类,并且可能很难控制它们。为此,您可以检查产品循环中是否存在产品,或者是否存在要从产品页面中删除的产品,如下所示:

    add_filter( 'post_class', function($classes){
    $product = wc_get_product();
    return ($product) ? array('product'  'or-any-class-you-want') : $classes; } , 9999 );
    

    我建议对post_类函数应用一个过滤器,而不是编辑模板,因为woocommerce会定期更新这些模板,如果一直保持在它们之上,可能会很痛苦。为此,您可以检查产品循环中是否存在产品,或者是否存在要从产品页面中删除的产品,如下所示:

    add_filter( 'post_class', function($classes){
    $product = wc_get_product();
    return ($product) ? array('product'  'or-any-class-you-want') : $classes; } , 9999 );
    

    在woocommerce插件“3.6.2”中,文件“wc template functions.php”显示:

    //注意,要更改类,您需要使用更新的woocommerce\u post\u类过滤器

    因此,要删除我使用的“first”和“last”类:

    add_filter( 'woocommerce_post_class', 'remove_post_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_post_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    
    add_filter( 'product_cat_class', 'remove_category_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_category_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    
    对于我使用的产品类别:

    add_filter( 'woocommerce_post_class', 'remove_post_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_post_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    
    add_filter( 'product_cat_class', 'remove_category_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_category_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    

    在woocommerce插件“3.6.2”中,文件“wc template functions.php”显示:

    //注意,要更改类,您需要使用更新的woocommerce\u post\u类过滤器

    因此,要删除我使用的“first”和“last”类:

    add_filter( 'woocommerce_post_class', 'remove_post_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_post_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    
    add_filter( 'product_cat_class', 'remove_category_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_category_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    
    对于我使用的产品类别:

    add_filter( 'woocommerce_post_class', 'remove_post_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_post_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    
    add_filter( 'product_cat_class', 'remove_category_class', 21, 3 ); //woocommerce use priority 20, so if you want to do something after they finish be more lazy
    function remove_category_class( $classes ) {
        if ( 'product' == get_post_type() ) {
            $classes = array_diff( $classes, array( 'last','first' ) );
        }
        return $classes;
    }
    

    几门课程如何降低网站的速度?你做过任何性能测试吗?@SamvelAleqsanyan是的,听起来很奇怪,但我们谈论的是来自指定类别(层次结构)的数百个类以及添加到每个产品的属性。我改变了,几个课程是如何让网站变慢的?你做过任何性能测试吗?@SamvelAleqsanyan是的,听起来很奇怪,但我们谈论的是来自指定类别(层次结构)的数百个类以及添加到每个产品的属性。我更改了您应该提供有问题的文件的名称(以及在何处查找)。content-product。php@JinHuang看到您的评论太晚了,但您是对的,content-product.php是我们更改这一行的地方,如果您需要我,随时Ping me:)您应该提供的名称(以及在哪里可以找到)正在讨论的文件。content-product。php@JinHuang看到您的评论太晚了,但您是对的,content-product.php是我们更改这一行的地方,如果您需要我,随时Ping我:)