How can I enable customer selection during the order process on the WooCommerce frontend? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 hours ago. Improve this question I'm currently using WooCommerce for online store, and I'm looking for a way to allow store managers or administrators to select customers directly from the frontend while placing an order. Right now, it seems that customer selection is only possible through the backend, but I need this functionality to be available during the frontend ordering process. Here's the situation: When placing an order on behalf of a customer, I want the option to choose an existing customer from the customer list, rather than manually entering their details each time. Ideally, the customer selection dropdown or search bar should appear on the checkout page or a custom order form on the frontend. I'm open to using plugins or custom code to achieve this, but I'm unsure where to start or which tools would be best suited for this purpose.

Comment (1)

Jese Leos

August 24, 2024

Verified user

1. Add a Customer Dropdown to the Checkout Page // Admin Customer Selection WooCommerce function add_customer_selection_field_for_admin() { if (current_user_can('administrator')) { $customers = get_users(array('role__in' => array('customer', 'subscriber'))); echo '<p class="form-row form-row-wide">'; echo '<label for="customer_selection">' . __('Select Customer') . '</label>'; echo '<select required name="customer_selection" id="customer_selection">'; echo '<option value="">' . __('Select a customer') . '</option>'; foreach ($customers as $customer) { echo '<option value="' . esc_attr($customer->ID) . '">' . esc_html($customer->display_name . ' (' . $customer->user_email . ')') . '</option>'; } echo '</select>'; echo '</p>'; } } add_action('woocommerce_before_order_notes', 'add_customer_selection_field_for_admin'); 2. Set Checkout Selected Customer to particular order function assign_order_to_selected_customer($order_id) { if (current_user_can('administrator') && isset($_POST['customer_selection']) && !empty($_POST['customer_selection'])) { $customer_id = absint($_POST['customer_selection']); if ($customer_id) { update_post_meta($order_id, '_customer_user', $customer_id); } } } add_action('woocommerce_checkout_update_order_meta', 'assign_order_to_selected_customer');

You’ll be in good company