Sorting in Cart
-
Hi,
Payment in cart order etc. I’m having problems with situations. I found a resource for this as follows. But this doesn’t always work as other people have said. Do you have a solution?
Thank you.add_action( 'woocommerce_cart_loaded_from_session', 'sort_cart_items_by_vendor', 100 ); function sort_cart_items_by_vendor() { $items_to_sort = $cart_contents = array(); // Initializing // Loop through cart items foreach ( WC()->cart->cart_contents as $item_key => $cart_item ) { $vendor_id = get_post_field( 'post_author', $cart_item['product_id']); $store_info = dokan_get_store_info( $vendor_id ); $items_to_sort[ $item_key ] = $store_info['store_name']; } ksort( $items_to_sort ); // Loop through sorted items key foreach ( $items_to_sort as $cart_item_key => $store_name ) { $cart_contents[ $cart_item_key ] = WC()->cart->cart_contents[ $cart_item_key ]; } // Set sorted items as cart contents WC()->cart->cart_contents = $cart_contents; }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Sorting in Cart’ is closed to new replies.