'Get value of woocommerce_form_field

I have a woocommerce_form_field like the following:

 woocommerce_form_field('delivery_postcode', array(
            'type' => 'text',
            'Maxlength'=> 70,
            'class' => array( 'my-field-class form-row-wide') ,
            'label' => __('Where should we send it to? (postcode)') ,
            'required' => true,
        ) , '');

I want to grab the variable that the user assigns here and assign it to the postcode value using something along the lines of:

$user = wp_get_current_user();
        $id = $user->ID;
        //update_user_meta( $id, "shipping_postcode", (int)$_POST['delivery_postcode'] );

However, $_POST['delivery_postcode'] gives me the error "Undefined array key". WC()->checkout->get_value('delivery_postcode') doesn't seem to work either. What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source