• Have just started working with hooks and actions. The code below creates an additional field on my checkout page, now I want to change the ‘type’ to ‘select’ (right?) so I can add options/dropdown box with 4 or 5 selection options. What is the code I should use to add the options and where do I insert it in the string below?

    add_action( ‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’ );

    function my_custom_checkout_field( $checkout ) {

    echo ‘<div id=”my_custom_checkout_field”><p> </p><h3 style=”color: #00896a;”>’ . __(‘How Did You Hear About Us?’) . ‘</h3>’;

    woocommerce_form_field( ‘How Did You Hear About Us?’, array(
    ‘type’ => ‘text’,
    ‘class’ => array(‘my-field-class form-row-wide’),
    ‘label’ => __(‘Fill in this field’),
    ‘placeholder’ => __(‘Enter something’),
    ), $checkout->get_value( ‘How Did You Hear About Us?’ ));

    echo ‘</div>’;

    }

  • The topic ‘Help with action code … add options for custom field in checkout’ is closed to new replies.