WooCommerce - excelling eCommerce
Checkout custom fields with select type (2 posts)

  1. oceanlies
    Posted 2 years ago #

    Im trying to solve this issue on my checkout page, the select box appear, you can choose an item, but when you submit the form, there is no custom field in the order email.

    I have googled alot and im not able to find the code to change to post a select value and not a text value.

    Thanks for any help.

     * Add the field to the checkout
    add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
    function my_custom_checkout_field( $checkout ) {
        echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
        woocommerce_form_field( 'my_field_name', array(
            'type'          => 'type',
            'class'         => array('my-field-class form-row-wide'),
    	'required' 		=> true,
            'label'         => __('Fill in this field'),
            'placeholder'       => __('Enter something'),
    	'options'     => array(
            'choice1' => __('choice1', 'woocommerce' ),
            'choice2' => __('choice2', 'woocommerce' )
            ), $checkout->get_value( 'my_field_name' ));
        echo '</div>';
     * Process the checkout
    add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
    function my_custom_checkout_field_process() {
        global $woocommerce;
        // Check if set, if its not set add an error.
        if (!$_POST['my_field_name'])
             $woocommerce->add_error( __('Please enter something into this new shiny field.') );
     * Update the order meta with field value
    add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
    function my_custom_checkout_field_update_order_meta( $order_id ) {
        if ($_POST['my_field_name']) update_post_meta( $order_id, 'My Field', esc_attr($_POST['my_field_name']));


  2. oceanlies
    Posted 2 years ago #

    Little mistake, its :

    'type'          => 'select',

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.