I want to add a custom field on the WooCommerce validation page, but for the selected products.
For example, if a customer has Product A in the basket, only if this custom field should appear in the WooCommerce checkout page.
I use the following code in functions.php to add a custom field:
add_action('woocommerce_before_order_notes', 'my_delivery_checkout_field');
function my_delivery_checkout_field( $checkout ) {
echo '<div id="my_local_club"><h3>'.__('Delivery Options').'</h3>';
woocommerce_form_field( 'delivery_options', array(
'type' => 'select',
'class' => array('my-club-class form-row-wide'),
'label' => _('<br><br>Please select your options', 'woocommerce'),
'required' => true,
'placeholder' => _x('Please Select An Option...', 'placeholder','woocommerce'),
'options' => array(
'option1' => 'Option 1',
'option_2' =>'Option 2',
'option_3' =>'Option 3'
)
), $checkout->get_value( 'delivery_options' ));
echo '</div>';
}
source
share