[英]How to hide some Custom Fields from Woocommerce Admin order page
When logged in as an admin and looking at an Order in Woocommerce, there's a section with all the Custom Fields.当以管理员身份登录并查看 Woocommerce 中的订单时,会有一个包含所有自定义字段的部分。 Out of the whole list I only want it to display two of them.
在整个列表中,我只希望它显示其中两个。 How do I hide the rest from this view?
我如何从这个视图中隐藏其余部分? I don't want to delete them, but just hide from this view.
我不想删除它们,只是从这个视图中隐藏。
For every custom field you want hidden, add the following 4 lines of code to functions.php or using Snippets plugin:对于您想要隐藏的每个自定义字段,将以下 4 行代码添加到 functions.php 或使用 Snippets 插件:
add_filter('is_protected_meta', 'my_is_protected_meta_filter1', 10, 2);
function my_is_protected_meta_filter1($protected, $meta_key) {
return $meta_key == 'automatewoo_cart_id' ? true : $protected;
}
If you want to hide more than one, add the lines above again and change 'my_is_protected_meta_filter1' to 'my_is_protected_meta_filter2', etc如果要隐藏多个,请再次添加上面的行并将“my_is_protected_meta_filter1”更改为“my_is_protected_meta_filter2”等
if you're using ACF pro , there is a hook you can use to remove the field on the back end, but it's not something that's documented..如果您使用的是ACF pro ,则可以使用一个挂钩来删除后端的字段,但这不是记录在案的内容。
You could use a hook to remove specific field if is_admin() returns true.如果 is_admin() 返回 true,您可以使用挂钩删除特定字段。
You may need to play with this a bit to get it to work, the ACF hook is您可能需要稍微尝试一下才能使其正常工作,ACF 钩子是
acf/get_fields
So, for example:因此,例如:
add_filter('acf/get_fields', 'your_function_name', 20, 2);
function your_function_name($fields, $parent) {
// remove the fields you don't want
return $fields;
}
$fields can be a nested array of fields => sub_fields. $fields 可以是字段的嵌套数组 => sub_fields。
You need to set the priority > 10 to run after the internal ACF filter您需要设置优先级> 10才能在内部 ACF 过滤器之后运行
For orders in Woocommerce the post type is 'shop_order', so your code should be:对于 Woocommerce 中的订单,帖子类型为“shop_order”,因此您的代码应为:
add_action( 'add_meta_boxes', 'remove_shop_order_meta_boxe', 90 );
function remove_shop_order_meta_boxe() {
remove_meta_box( 'postcustom', 'shop_order', 'normal' );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.