79718493

Date: 2025-07-29 11:08:12
Score: 4
Natty: 4.5
Report link

Can someone pls modify the code below to work with the latest version of Woocommerce V 10.0 ?

/**
 * Use multiple sku's to find WOO products in wp-admin
 * NOTE: Use '|' as a sku delimiter in your search query. Example: '1234|1235|1236'
**/
function woo_multiple_sku_search( $query_vars ) {

    global $typenow;
    global $wpdb;
    global $pagenow;

    if ( 'product' === $typenow && isset( $_GET['s'] ) && 'edit.php' === $pagenow ) {
        $search_term = esc_sql( sanitize_text_field( $_GET['s'] ) );

        if (strpos($search_term, '|') == false) return $query_vars;

        $skus = explode('|',$search_term);

        $meta_query = array(
            'relation' => 'OR'
        );
        if(is_array($skus) && $skus) {
            foreach($skus as $sku) {
                $meta_query[] = array(
                    'key' => '_sku',
                    'value' => $sku,
                    'compare' => '='
                );
            }
        }

        $args = array(
            'posts_per_page'  => -1,
            'post_type'       => 'product',
            'meta_query'      => $meta_query
        );
        $posts = get_posts( $args );

        if ( ! $posts ) return $query_vars;

        foreach($posts as $post){
          $query_vars['post__in'][] = $post->ID;
        }
    }

    return $query_vars;
}
add_filter( 'request', 'woo_multiple_sku_search', 20 );

It's a very useful script to bulk update the 'product category' after searching multiple SKU's from the dashboard admin.

Thanks in Advance.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (3): Thanks in Advance
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Can someone
  • Low reputation (1):
Posted by: Maverick_27