1

I am using this to create a new field in my woocommerce billing form

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
    );

and also i use this code to do action after payment:

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 );

}

the question is how can i get that mobile number which user enter before payment in my "create_invoice_for_wc_order" function?

Mohammad
  • 722
  • 1
  • 8
  • 17

1 Answers1

1

After $order = wc_get_order( $order_id ); try:

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

There should be your billing_mobile field

  • i var_dum it and it's show it: https://gist.github.com/anonymous/b7aae4a04bcb58fddae752ac95c22f2d but how can i save it ? it's an object in array – Mohammad Sep 16 '17 at 12:00
  • Your field in meta_data property. So after $order_data = $order->get_data(); add $billing_mobile = ''; foreach($order_data['meta_data'] as $meta) {if($meta->key == '_billing_mobile') {$billing_mobile = $meta->value; break;}} – Leonid Serdiuk Sep 16 '17 at 12:06