在WooCommerce中创建手动订单时,我需要使用他们的电话详细信息来搜索客户。我尝试过:
add_filter( 'woocommerce_shop_order_search_fields', 'custom_billing_phone_search_fields', 10, 1 );
function custom_billing_phone_search_fields( $meta_keys ){
$meta_keys[] = '_billing_phone';
return $meta_keys;
}
jQuery(document).ready(function($) {
$(document).on('select2:open', '.wc-customer-search', function() {
$('.select2-search__field').attr('placeholder', 'Search by name or phone number');
});
});
jQuery(document).ready(function($) {
$(document).on('select2:open', '.wc-customer-search', function() {
$('.select2-dropdown').html('<input type="text" class="select2-search__field" placeholder="Search by name or phone number">');
var customers = $('.select2-results__option');
$('.select2-search__field').on('keyup', function() {
var searchKeyword = $(this).val().toLowerCase().trim();
customers.each(function() {
var customerName = $(this).text().toLowerCase();
var customerPhone = $(this).data('phone').toLowerCase();
if (customerName.includes(searchKeyword) || customerPhone.includes(searchKeyword)) {
$(this).show();
} else {
$(this).hide();
}
});
});
});
});
和
function custom_woocommerce_customer_search_by_phone( $search_fields ) {
$search_fields[] = 'billing_phone';
$search_fields[] = 'shipping_phone';
return $search_fields;
}
add_filter( 'woocommerce_admin_order_data_after_billing_address', 'custom_woocommerce_customer_search_by_phone' );
但这些都不允许我搜索电话号码,只会弹出用户名、电子邮件或姓名。请协助
尝试了上述所有代码段,但均未返回结果