Php 在woocommerce中支付后获取元数据

Php 在woocommerce中支付后获取元数据,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在使用它在我的woocommerce账单表单中创建一个新字段 add_filter('woocommerce_checkout_fields', array(__CLASS__,'custom_woocommerce_billing_fields')); function custom_woocommerce_billing_fields($fields) { $fields['billing']['billing_mobile'] = array( 'label'

我正在使用它在我的woocommerce账单表单中创建一个新字段

add_filter('woocommerce_checkout_fields', array(__CLASS__,'custom_woocommerce_billing_fields'));
function custom_woocommerce_billing_fields($fields)
{
    $fields['billing']['billing_mobile'] = array(
        'label' => __('Mobile Phone Number', 'woocommerce'), // Add custom field label
        'placeholder' => _x('Mobile Phone Number', 'placeholder', 'woocommerce'), // Add custom field placeholder
        'required' => true, // if field is required or not
        'clear' => false, // add clear or not
        'type' => 'text', // add field type
        'class' => array('my-css')   // add class name
    );
我还使用此代码在付款后执行操作:

add_action( 'woocommerce_payment_complete', array(__CLASS__,'create_invoice_for_wc_order'));
function create_invoice_for_wc_order( $order_id ) { 
    // get order details data...
    $order = wc_get_order( $order_id );

}

问题是如何在我的“为wc订单创建发票”功能中获得用户在付款前输入的手机号码?

在$order=wc\U get\U order($order\U id)之后;尝试:


应该有你的
billing\u mobile
字段

i var\u dum它和它的show it:但是我怎么能保存它呢?它是元数据属性中arrayYour字段中的一个对象。所以在$order_data=$order->get_data()之后;添加$billing_mobile='';foreach($order_data['meta_data']as$meta){if($meta->key=='u billing_mobile'){$billing_mobile=$meta->value;break;}
$order_data = $order->get_data();
print_r($order_data);