Search for custom field
-
How can we search for a value from the custom fields?
We have ‘billing_leerlingnr’ as a custom field. We try to find this value in the WooCommerce order search, but is doesn’t show any results:
add_filter( 'woocommerce_shop_order_search_fields', 'VF_search_custom_fields' );
function VF_search_custom_fields( $search_fields ) {
$search_fields[] = '_billing_leerlingnr';
return $search_fields;
}Is there a solution to be able to show the custom data after search in Woocommerce > Orders?
add_filter( 'woocommerce_shop_order_search_results', 'VF_search_leerlingnr_field', 10, 3 );
function VF_search_leerlingnr_field( $order_ids, $term, $search_fields ) {
global $wpdb;
$query = $wpdb->prepare(
"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_th_wccl_customized_fields' AND meta_value LIKE %s",
'%' . $wpdb->esc_like( $term ) . '%'
);
$results = $wpdb->get_col( $query );
if ( $results ) {
$order_ids = array_unique( array_merge( $order_ids, $results ) );
}
return $order_ids;
}
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Search for custom field’ is closed to new replies.