【问题标题】:Get meta data after payment in woocommerce [duplicate]在woocommerce中付款后获取元数据[重复]
【发布时间】:2018-02-25 11:10:39
【问题描述】:

我正在使用它在我的 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 );

}

问题是如何在“create_invoice_for_wc_order”函数中获取用户在付款前输入的手机号码?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    $order = wc_get_order( $order_id ); 之后试试:

    $order_data = $order->get_data();
    print_r($order_data);
    

    应该有你的billing_mobile 字段

    【讨论】:

    • i var_dum 并显示它:gist.github.com/anonymous/b7aae4a04bcb58fddae752ac95c22f2d 但我怎样才能保存它?它是数组中的一个对象
    • 您在 meta_data 属性中的字段。所以在 $order_data = $order->get_data();添加 $billing_mobile = ''; foreach($order_data['meta_data'] as $meta) {if($meta->key == '_billing_mobile') {$billing_mobile = $meta->value;打破;}}
    猜你喜欢
    • 2018-06-24
    • 2016-08-26
    • 2017-08-27
    • 2019-02-22
    • 2019-03-10
    • 1970-01-01
    • 2017-04-08
    • 2021-09-04
    • 2021-08-20
    相关资源
    最近更新 更多