0

I am trying to add a dropdown at checkout allows the customer to select their pickup location when they choose local pickup as their shipping option. The code that I have now works as far as displaying the drop down at checkout but I need to add validation to make sure that if local pickup is selected that a drop down option is selected. Additionally I want the selected option to be visible in the admin order panel.

//* Add select field to the checkout page
add_action('woocommerce_after_shipping_rate', 'local_pickup_location');
function local_pickup_location( $method ) {
    
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_no_ajax = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {
    if( 'local_pickup:15' === $method->id ) {
        ?>
        <form name="localpickup" method="post">
        <select id="pickupoptions" name="pickup" style="background-color: white;" onchange="this.form.submit()">
        <option value="" selected disabled hidden>Select your pickup location</option>
        <option value="hampton">Wisephone ER Hampton</option>
        <option value="norfolk">Wisephone ER Norfolk</option>
        </select>
        </form>
        <?php
        }
   }
}

Any help is greatly appreciated!

0 Answers0