Checkout field does not appear in the order object

Asked

Viewed 81 times

1

I’m having a problem with the object order of wordpress. After making the purchase, the order object does not come with the value entered in the field. The CPF field is created by me, follow the code:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
  $fields['billing']['billing_cpf'] = array(
      'label'     => __('CPF', 'woocommerce'),
      'required'  => true,
      'class'     => array('input-text'),
      'clear'     => true,
      'type'     => "text",
      "name" => "billing_cpf",
  );
  return $fields;
}

The field appears on the screen, but its value is not sent in the array $order->data['billing']. How do I receive its value? I’m using the plugin Woocommerce, and created another (plugin) to make these changes.

1 answer

0

To solve this, you can use the function get_post_meta, for this, use the following syntax: get_post_meta( $order_id, '_billing_cpf', true ), this will return the value inserted in the input!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.