This snippet for WordPress Multisite adds custom search functionality that allows administrators to search for products by their SKU (Stock Keeping Unit) across the entire network. This feature is particularly useful for networks that manage multiple e-commerce sites and need a centralized way to locate products based on their SKU or for those who sell the same product across multiple sites.
SKU Search
blog_id );
$query = new WC_Product_Query( [
'limit' => -1,
'sku' => $sku,
] );
$products = $query->get_products();
foreach ( $products as $p ) {
$product_id = $p->get_id();
$product_name = $p->get_name();
$blog_name = get_blog_option( $b->blog_id, 'blogname' );
$edit_url = get_admin_url( $b->blog_id, "post.php?post={$product_id}&action=edit" );
echo esc_html( $b->blog_id ) . ' ';
echo ''
. esc_html( $blog_name . ' - ' . $product_name )
. '
';
}
restore_current_blog();
}
}
}
?>