我想在WooCommerce订单页面上添加自定义搜索。怎么可能?

时间:2015-10-14 09:48:19

标签: woocommerce

我使用了这段代码但没有任何反应。

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'));
});

0 个答案:

没有答案