Ecommerce Shopify WordPress Discussion

Filter orders by specific meta value that does not match specific strings in Woocommerce admin order list

I need to create a filter on the order list based on a specific meta key + value. I followed this post and it helped tremendously. However, I need to create a filter that fits this rule: Show orders that have meta key: '_created_via' with a value that is NOT 'admin' or 'checkout'. Is there a way to filter meta_value with not match specific strings? See: $vars['meta_value'] = <NOT 'checkout' or 'admin'> // Process the filter dropdown for orders add_filter( 'request', 'process_admin_shop_order_marketing_by_meta', 99 ); function process_admin_shop_order_marketing_by_meta( $vars ) { global $pagenow, $typenow; $filter_id = 'filter_shop_order_by_meta'; if ( $pagenow == 'edit.php' && 'shop_order' === $typenow && isset( $_GET[$filter_id] ) && ! empty($_GET[$filter_id]) ) { $vars['meta_key'] = $_GET[$filter_id]; $vars['orderby'] = 'meta_value'; if ($_GET[$filter_id] == '_created_via') { $vars['meta_value'] = <NOT 'checkout' or 'admin'> } } return $vars; }
Looking at WP_Query documentation for "custom field post meta parameters", you can use meta_compare defined to "NOT IN" and meta_value defined with an array of values… Try the following (untested): add_filter( 'request', 'process_admin_shop_order_marketing_by_meta', 99 ); function process_admin_shop_order_marketing_by_meta( $vars ) { global $pagenow, $typenow; $filter_id = 'filter_shop_order_by_meta'; if ( 'edit.php' === $pagenow && 'shop_order' === $typenow && isset( $_GET[$filter_id] ) && ! empty($_GET[$filter_id]) ) { $vars['meta_key'] = $_GET[$filter_id]; $vars['orderby'] = 'meta_value'; if ($_GET[$filter_id] === '_created_via') { $vars['meta_compare'] = 'NOT IN'; $vars['meta_value'] = array( 'checkout', 'admin' ); } } return $vars; } It could work.

January 7, 2024

Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.