• Resolved loopforever

    (@loopforever)


    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;
    }

    Resource:

Viewing 5 replies - 1 through 5 (of 5 total)
  • Shafinoid

    (@shafinahmad01)

    Hello @loopforever
    Thank you for reaching us.

    I would like to provide you with a better solution however, to respect our support policy, we cannot provide any custom solutions. I believe you can understand that.

    Have a nice day!

    Thread Starter loopforever

    (@loopforever)

    Support policy ? I am here for him.

    If there is more than one vendor, I cannot properly store the data that will be needed in the future.
    I don’t want him to write code. What can I do ?

    Thread Starter loopforever

    (@loopforever)

    Thank you.

    • This reply was modified 3 years, 1 month ago by loopforever.
    • This reply was modified 3 years, 1 month ago by loopforever.
    • This reply was modified 3 years, 1 month ago by loopforever.
    • This reply was modified 3 years, 1 month ago by loopforever.
    Shafinoid

    (@shafinahmad01)

    Hello @loopforever

    I can understand that solution might be important to you. As you are having trouble manipulating data from the database in that case I will recommend you hire expert developers. I would like to review your custom solution or provide you with one however, as you know I cannot do that.

    I am just respecting our support policy by not reviewing/providing any custom solutions. If you need any further information or assistance then feel free to contact us from here.

    Kind Regards!

    Shafinoid

    (@shafinahmad01)

    Hi,

    I believe you are doing well. As you haven’t replied for a long, I’m considering that your query is being satisfied and I’m also resolving this topic.

    But feel free to create another one anytime.`

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sorting in Cart’ is closed to new replies.