1

I used this code but nothing happens.

add_filter( 'woocommerce_shop_order_search_fields', function ($search_fields ) {
$posts = get_posts(array('post_type' => 'shop_order'));

foreach ($posts as $post) {
    $order_id = $post->ID;
    $order = new WC_Order($order_id);
    $items = $order->get_items();

    foreach($items as $item) {
        $product_id = $item['product_id'];
        $search_sku = get_post_meta($product_id, "_sku", true);
        add_post_meta($order_id, "_product_sku", $sku);
        add_post_meta($order_id, "_product_id", $product_id);
    }
}

return array_merge($search_fields, array('_product_sku', '_product_id'));
});
il_raffa
  • 5,090
  • 129
  • 31
  • 36
  • In the admin or on the front end? What are you trying to search for? Please expand your question a bit. – helgatheviking Oct 14 '15 at 15:25
  • Nevermind, I see that this is a duplicate of [this](http://stackoverflow.com/q/28063920/383847). Not sure that the selected answer would really work as you are discovering. As I said on that thread the SKU and product ID for orders aren't saved as meta for the order. – helgatheviking Oct 14 '15 at 15:33
  • Thanks for reply... but i had found the solution for this... – Dedar Singh Oct 15 '15 at 10:27
  • You should post your solution for someone else with the same problem. – helgatheviking Oct 15 '15 at 13:47

0 Answers0