删除/隐藏 total_sales WooCommerce 自定义字段 [英] Remove/hide total_sales WooCommerce custom field

查看:24
本文介绍了删除/隐藏 total_sales WooCommerce 自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在显示产品的 the_meta 时删除 total_sales 自定义字段?

Is there a way to remove the total_sales custom field when displaying the_meta for a product?

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

I can change the entry in the editor to another name and value, but it magically appears again and won't be deleted.

推荐答案

我会为此使用 'the_meta_key' 过滤器.你有几个选项,当然你可以组合它们.

I would use the 'the_meta_key' filter for this. you have a few options, and of course you can combine them.

控制用 CSS 隐藏什么

Control what to hide with 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

Control what to hide via 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 控制要显示的内容

Control what to Display with 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 控制不显示的内容

Control what not to Display with 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;
    }
}

这篇关于删除/隐藏 total_sales WooCommerce 自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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