F
F
Fleepay2021-06-16 08:07:51
WooCommerce
Fleepay, 2021-06-16 08:07:51

How to sort products by SKU on order page in WooCommerce admin?

Good afternoon!

For faster assembly of orders, where the quantity of goods is more than 10 pcs. (goods in the warehouse are by Article) you need to sort the goods by Article on the order page in the admin panel.
Maybe someone has a suggestion to solve this issue.

60c985a8bb6e1150665368.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Chernenko, 2021-06-16
@Fleepay

Sort them in the basket, it will be written to the database in the right order:

function sort_cart_sku() {
    $in_cart = array();
    foreach ( WC()->cart->get_cart_contents() as $key => $item ) {
        $in_cart[ $key ] = $item['data']->get_sku();
    }
    natsort( $in_cart );
    $cart_items = array();
    foreach ( $in_cart as $cart_key => $product_title ) {
        $cart_items[ $cart_key ] = WC()->cart->cart_contents[ $cart_key ];
    }
    WC()->cart->cart_contents = $cart_items;
}
add_action( 'woocommerce_cart_loaded_from_session',  'sort_cart_sku' );

*Of course, it will only work for new orders)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question