Answer the question
In order to leave comments, you need to log in
How to sort goods after placing an order not through SKU?
I have a code, but I need help on how to remake it so that products are sorted by category (Currently they are sorted by SKU)
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' );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question