久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 WooCommerce 訂單管理頁面中按訂單項(xiàng) SKU 或 ID 搜

Search by order item SKU or ID in WooCommerce Orders Admin page(在 WooCommerce 訂單管理頁面中按訂單項(xiàng) SKU 或 ID 搜索)
本文介紹了在 WooCommerce 訂單管理頁面中按訂單項(xiàng) SKU 或 ID 搜索的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想要做的是能夠在 WooCommerce 訂單管理頁面中按訂單商品 SKU 或 ID 進(jìn)行搜索.

What I am trying to do is to be able to search by order item SKU or ID in the WooCommerce Orders Admin page.

到目前為止我發(fā)現(xiàn)/完成的,但沒有成功的是 functions.php 文件中的以下內(nèi)容.

What I have found/done till now, but with no success is the following at functions.php file.

add_filter( 'woocommerce_shop_order_search_fields', 'woocommerce_shop_order_search_sku' );

function woocommerce_shop_order_search_sku( $search_fields ) {

    $args = array( 'post_type' => 'shop_order' );

    $orders = new WP_Query( $args );

    if ( $orders->have_posts() ) {
        while( $orders->have_posts() ) {
            $post = $orders->the_post();
            $order_id = get_the_ID();
            $order = new WC_Order( $order_id );
            $items = $order->get_items();
            foreach( $items as $item ) {
                $search_order_item_sku = wp_get_post_terms( $item['product_id'], 'search_sku' );
                foreach( $search_order_item_sku as $search_sku ) {
                    add_post_meta( $order_id, "_search_sku", $search_sku->sku );
                }
            }
        }
    };

    $search_fields[] = '_search_sku';

    return $search_fields;

}

我想問題在于 $search_skuadd_post_meta 所在行的值.

I suppose the issue is the value of $search_sku at the line with the add_post_meta.

我也用 get_sku()、$item['sku'] 嘗試過,但沒有成功.

I have also tried it with get_sku(), $item['sku'] with no luck.

推薦答案

@blacksquare、@jibby、@helgatheviking 你們是男人!由于您的幫助,這是有效的代碼.

@blacksquare, @jibby, @helgatheviking you are the men! This is the code that works, due to your help.

    //Search by product SKU in Admin Woocommerce Orders
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", $search_sku);
        }
    }

    return array_merge($search_fields, array('_product_sku'));
});

這篇關(guān)于在 WooCommerce 訂單管理頁面中按訂單項(xiàng) SKU 或 ID 搜索的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 久久国产精品视频 | 国产成人精品一区二区三区网站观看 | 亚洲91精品| 欧美日韩精品免费 | 亚洲视频免费在线看 | 亚洲精品乱码久久久久久蜜桃 | 色吧久久 | 欧美成人精品 | 日韩在线免费看 | 日韩欧美一区二区三区四区 | 日韩综合一区 | 91精品国产91久久久久游泳池 | www.日日夜夜 | 亚洲福利免费 | 九九热九九 | 玖玖玖在线 | 久久久精品天堂 | 国产精品18久久久久久久 | 日韩欧美三区 | 国产综合精品一区二区三区 | av片网站| 天天爽夜夜爽精品视频婷婷 | 黄色精品 | 国产农村妇女毛片精品久久麻豆 | 亚洲中午字幕 | 自拍亚洲| 国产999精品久久久久久 | 欧美国产精品一区二区三区 | a久久 | 亚洲欧美精品国产一级在线 | 国产成人精品久久二区二区91 | 国产成人福利在线观看 | 成人av一区 | 亚州视频在线 | 在线看无码的免费网站 | 天天干天天操天天看 | 久久国产麻豆 | 97人人草| 精品一区二区三区在线观看 | 国产伦精品一区二区三区精品视频 | 精品国产18久久久久久二百 |