I’ve been trying to add a new filter to my WooCommerce orders table based on vendors. I successfully connected the WCFM vendors list to a dropdown menu, allowing users to select a vendor. However, when a vendor is selected, it does not display the related orders and instead shows a message stating that no orders are available. I believe the query is correct since it does show the list of orders.
Thank you for your assistance!
add_action( 'pre_get_posts', 'wcfm_filter_orders_by_store' );
function wcfm_filter_orders_by_store( $query ) {
global $typenow;
if ( 'shop_order' === $typenow && is_admin() && isset( $_GET['wcfm_store_filter'] ) && ! empty( $_GET['wcfm_store_filter'] ) ) {
$store_id = intval( $_GET['wcfm_store_filter'] );
$meta_query = array(
array(
'key' => '_vendor_id', // Assuming this is the correct meta key
'value' => $store_id,
'compare' => '=',
)
);
$existing_meta_query = $query->get( 'meta_query' );
if ( is_array( $existing_meta_query ) ) {
$meta_query = array_merge( $existing_meta_query, $meta_query );
}
$query->set( 'meta_query', $meta_query );
}
}
1