
I’m trying to populate an order field with options set on our checkout form.
function custom_field_value( $checkout ) {
$field_key = "field_xxxxxxxxxxxxx";
$field = get_field_object($field_key);
if( $field ) {
echo '<div id="custom_field_value">';
woocommerce_form_field( 'custom_field_value', array(
'type' => 'select',
'class' => array('custom_field_value form-row-wide'),
'label' => __('Descriptive Name'),
'required' => true,
'options' => $field['choices']
), $checkout->get_value('custom_field_value'));
echo '</div>';
}
}
add_action( 'woocommerce_after_checkout_billing_form', 'custom_field_value' );
add_action( 'woocommerce_checkout_update_order_meta', 'populate_custom_field_value' );
function populate_custom_field_value( $order_id ) {
if ( ! empty( $_POST['custom_field_value'] ) ) {
update_field( 'field_xxxxxxxxxxxxx', sanitize_text_field( $_POST['custom_field_value'], $order_id ));
}
}
But even though my selector is inserted correctly, it’s not setting the field on the order.
Can anyone see what I’m missing here?