Customize autocomplete results
(+ user meta field SavingsID)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
if( isset( $_GET['wpo_find_customer'] ) ) { add_filter( "woocommerce_json_search_found_customers", function($customers){ foreach($customers as $key=>$data) { if($data['type'] == 'order' ) { $order = new WC_Order($data['id']); $title = sprintf( esc_html__( '%1$s (#%2$s – %3$s)', 'phone-orders-for-woocommerce' ), implode( ' ', array( current( array_filter( array( $order->get_billing_first_name(), $order->get_shipping_first_name(), ) ) ), current( array_filter( array( $order->get_billing_last_name(), $order->get_shipping_last_name(), ) ) ), ) ), get_user_meta($order->get_customer_id(), "SavingsID", true), $order->get_billing_address_1() ); } elseif($data['type'] == 'customer' ) { $customer = new WC_Customer($data['id']); $title = sprintf( esc_html__( '%1$s (#%2$s – %3$s)', 'phone-orders-for-woocommerce' ), implode( ' ', array( current( array_filter( array( $customer->get_billing_first_name(), $customer->get_shipping_first_name(), ) ) ), current( array_filter( array( $customer->get_billing_last_name(), $customer->get_shipping_last_name(), ) ) ), ) ), get_user_meta($data['id'], "SavingsID", true), $customer->get_billing_address_1() ); } $customers[$key]['title'] = $title; } return $customers; },100); } |