Created
May 23, 2020 17:37
-
-
Save gstreetmedia/2963d96811d36fc667dba24df464d89b to your computer and use it in GitHub Desktop.
Add _sku search to the product admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(is_admin()) { | |
| /** | |
| * @param $join | |
| * @return string | |
| */ | |
| function gstreet_woocommerce_join_sku($join) | |
| { | |
| global $pagenow, $wpdb; | |
| if ($pagenow == 'edit.php' && !empty($_GET['post_type']) && $_GET['post_type'] == 'product' && !empty($_GET['s'])) { | |
| $join .= 'LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . ".post_id AND {$wpdb->postmeta}.meta_key = '_sku' "; | |
| } | |
| return $join; | |
| } | |
| add_filter('posts_join', 'gstreet_woocommerce_join_sku'); | |
| /** | |
| * @param $where | |
| * @return string | |
| */ | |
| function gstreet_woocommerce_search_sku($where) | |
| { | |
| global $pagenow, $wpdb; | |
| if ($pagenow == 'edit.php' && !empty($_GET['post_type']) && $_GET['post_type'] == 'product' && !empty($_GET['s'])) { | |
| $where .= " OR {$wpdb->postmeta}.meta_value LIKE '{$_GET['s']}'"; | |
| } | |
| return $where; | |
| } | |
| add_filter('posts_where', 'gstreet_woocommerce_search_sku'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment