删除/隐藏 Total_sales WooCommerce 自定义字段

2024-01-11

有没有办法去除total_sales显示时自定义字段the_meta对于一个产品?

我可以将编辑器中的条目更改为其他名称和值,但它会神奇地再次出现并且不会被删除。


我会为此使用“the_meta_key”过滤器。您有几种选择,当然您可以将它们组合起来。

使用 CSS 控制隐藏内容

add_filter( 'the_meta_key' , 'class_custom_fields', 10, 3);

function classes_custom_fields($string, $key, $value){
    return str_replace('<li>','<li class="' . str_replace(' ', '-', $key). '">',$string);
}

<style>
ul.post-meta li.total_sales{
    display:none;
}
</style>

通过 PHP 和 CSS 控制隐藏内容

add_filter( 'the_meta_key' , 'hide_custom_fields', 10, 3);

function hide_custom_fields($string, $key, $value){
    $hide_keys = array(
        'total_sales'
    );
    if(in_array(strtolower($key), $hide_keys)){
        return str_replace('<li>','<li class="hide">',$string);
    }
    return $string;
}
<style>
    .hide{
        display:none;
    }
</style>

使用 PHP 控制显示内容

add_filter( 'the_meta_key' , 'allowed_custom_fields', 10, 3);

function allowed_custom_fields($string, $key, $value){

    $allowed_keys = array(
        'attribute one',
    );

    if(in_array(strtolower($key), $allowed_keys)){
        return $string;
    }
}

控制 PHP 不显示的内容

add_filter( 'the_meta_key' , 'disallowed_custom_fields', 10, 3);


function disallowed_custom_fields($string, $key, $value){

    $disallowed_keys = array(
        'total_sales'
    );
    if(!in_array(strtolower($key), $disallowed_keys)){
        return $string;
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

删除/隐藏 Total_sales WooCommerce 自定义字段 的相关文章

随机推荐