在Woocommerce管理订单页面中按SKU对订单项进行排序 [英] Sort order items by SKU in Woocommerce admin order pages

查看:97
本文介绍了在Woocommerce管理订单页面中按SKU对订单项进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能的话,我很沮丧.我想只在前端查看结果以按SKU排序.不是后端.当您编辑订单时,我希望有一个SKU列,可以按 ASC/DESC 进行排序.是否有实现此目的的插件,或者可以在其他栏中添加的代码段?任何帮助将不胜感激.下图显示了我正在谈论的SKU,希望将其移动/复制到自己的列中

I'm stumped if it's possible. I have scouted to only seeing results to sort by SKU on the front end. not the backend. When you edit an order, I want there to be an SKU column that I can sort by ASC/DESC. Is there a plugin out there that achieves this, or a snippet of code that can add in an additional column? Any help would be greatly appreciated. Below is an image illustrating the SKU I'm talking about and would love for it to be moved/duplicated into its own column

推荐答案

@mujuonly有一个很好的答案.在发现与woocommerce订阅续订发生冲突之前,我一直在使用它.原始订单很好,但续订订单缺少其运送方式.

@mujuonly has a great answer. I was using it until I found a conflict with woocommerce subscription renewals. The original orders were fine, but renewals orders were missing their shipping method.

相反,我选择按sku对购物篮项目进行排序,以便将它们以这种方式保存在数据库中.

Instead I opted to sort the basket items by sku so that they would be saved in the database that way.

add_action( 'woocommerce_cart_loaded_from_session', 'sort_cart_items_sku' );

function sort_cart_items_sku() {

    // READ CART ITEMS
    $products_in_cart = array();
    foreach ( WC()->cart->get_cart_contents() as $key => $item ) {
        $products_in_cart[ $key ] = $item['data']->get_sku();
    }

    // SORT CART ITEMS
    natsort( $products_in_cart );

    // ASSIGN SORTED ITEMS TO CART
    $cart_contents = array();
    foreach ( $products_in_cart as $cart_key => $product_title ) {
        $cart_contents[ $cart_key ] = WC()->cart->cart_contents[ $cart_key ];
    }
    WC()->cart->cart_contents = $cart_contents;

}

信用: https://businessbloomer.com/woocommerce-sort- cart-items-alphabetically-az/

这篇关于在Woocommerce管理订单页面中按SKU对订单项进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆