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 4 days ago. This post was edited and submitted for review 22 hours ago and failed to reopen the post: Original close reason(s) were not resolved Improve this question I'm running an online store using WooCommerce, and I need to allow store managers or administrators to select an existing customer directly from the front-end while placing an order. Currently, this functionality seems limited to the back-end, but I want it to be available on the checkout page or a custom order form on the front-end. Key requirements: Customer selection: Instead of manually entering customer details each time, I need a dropdown or search bar on the checkout page that allows selection from a list of existing customers. Front-end availability: The feature should be accessible during the front-end ordering process, either on the standard checkout page or a custom-built form. My attempts: I've explored various WooCommerce settings, but couldn't find an option for this. I'm open to using plugins or custom code, but I'm unsure where to start. *How can I implement this customer selection feature on the front-end? Are there specific plugins or custom code examples that can help achieve this?
Jese Leos
August 28, 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');