如何为 WooCommerce 订单页面(管理员)添加自定义字段? [英] How to add custom fields for WooCommerce order page (admin)?

查看:42
本文介绍了如何为 WooCommerce 订单页面(管理员)添加自定义字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 WooCommerce/Wordpress 中的订单添加几个输入字段.这些字段仅在管理页面上可见.怎么做?和页面/帖子一样吗?

I would like to add few input fields for the orders in WooCommerce/Wordpress. The fields will be only visible on the admin page. How to do that? Is it same like the pages/posts?

对于上述帖子类型,我使用了 add_post_meta.这是最好的方法,还是订单字段有任何钩子?

For the post types above I used add_post_meta. Is it the best way for that, or is there any hook for order fields?

推荐答案

是的,只需 add_meta_box() 到帖子类型 shop_order照常进行.

Yes, just add_meta_box() to the post type shop_order and proceed as normal.

add_action( 'add_meta_boxes', 'add_meta_boxes' );

function add_meta_boxes()
{
    add_meta_box( 
        'woocommerce-order-my-custom', 
        __( 'Order Custom' ), 
        'order_my_custom', 
        'shop_order', 
        'side', 
        'default' 
    );
}
function order_my_custom()
{
    echo '<h1>Sample meta box</h1>';
}

这篇关于如何为 WooCommerce 订单页面(管理员)添加自定义字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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