Woocommerce Custom Search Admin Panel Results
Question
Products: Latest version of WordPress, Woocommerce, ACF, Admin Columns PRO
I used Admin Columns PRO to add the ACF field columns to the Woocommerce Order Admin Panel. I added the following custom search code to functions.php to search the ACF fields.
function custom_search_join ($join){
global $pagenow, $wpdb;
$types = ['shop_order'];
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
$join .='INNER JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'custom_search_join' );
function custom_search_where( $where ){
global $pagenow, $wpdb;
$types = ['shop_order'];
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
$where .= " OR (".$wpdb->postmeta.".meta_key = 'batch' AND ".$wpdb->postmeta.".meta_value LIKE '%".$_GET['s']."%' )";
$where .= " OR (".$wpdb->postmeta.".meta_key = 'mum-order-number' AND ".$wpdb->postmeta.".meta_value LIKE '%".$_GET['s']."%' )";
$where .= " OR (".$wpdb->postmeta.".meta_key = 'school' AND ".$wpdb->postmeta.".meta_value LIKE '%".$_GET['s']."%' )";
$where .= " OR (".$wpdb->postmeta.".meta_key = 'type' AND ".$wpdb->postmeta.".meta_value LIKE '%".$_GET['s']."%' )";
$where .= " OR (".$wpdb->postmeta.".meta_key = 'delivery' AND ".$wpdb->postmeta.".meta_value LIKE '%".$_GET['s']."%' )";
$where .= " OR (".$wpdb->postmeta.".meta_key = 'color' AND ".$wpdb->postmeta.".meta_value LIKE '%".$_GET['s']."%' )";
}
return $where;
}
add_filter( 'posts_where', 'custom_search_where' );
I get the correct search results, but the ACF columns are empty on the return.
Any thoughts?
0
advanced-custom-fields, woocommerce
4 years
2019-10-28T14:40:33-05:00
2019-10-28T14:40:33-05:00 0 Answers
78 views
0
Leave an answer