简体   繁体   English

如何从 Woocommerce 管理订单页面隐藏一些自定义字段

[英]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.

相关问题 如何为 WooCommerce 订单页面(管理员)添加自定义字段? - How to add custom fields for WooCommerce order page (admin)? Woocommerce 自定义字段:部分值不在订单页面 - Woocommerce custom fields: some values are not in the order page 隐藏管理订单页面上订单项目的元数据 (WooCommerce) - Hide meta data from Order Items on Admin Order Page (WooCommerce) 显示自定义动态字段存储数据 woocommerce 订单管理和来自元的感谢页面。? - Display custom dynamic fields stored data woocommerce order admin and thankyou page from meta.? 如何使用自定义用户角色隐藏 woocommerce 订单管理员的退款按钮 - How to Hide Refund button on woocommerce order admin with custom user role 如何使用woocommerce从管理产品页面显示/隐藏某些类别? - how can I show/hide some categories from the admin product page using woocommerce? Wordpress WooCommerce管理员自定义订单字段 - Wordpress WooCommerce admin-custom-order-fields WooCommerce 中的自定义按钮添加订单管理页面 - Custom Button in WooCommerce add order admin page WooCommerce:将自定义 Metabox 添加到管理订单页面 - WooCommerce : Add custom Metabox to admin order page 向管理页面顺序添加一些可编辑的字段 - Adding some editable fields to admin page order
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM