• Resolved Wayn

    (@shnactor1)


    Is there a way to reverse the order of the items in Woocommerce Basket? I want the last items added to appear at the top of the cart.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,
    Add this code to your child theme’s functions.php

    
    add_action( 'woocommerce_cart_loaded_from_session', function() {
        global $woocommerce;
    	
    	$products_in_cart = array();
        foreach ( $woocommerce->cart->cart_contents as $key => $item ) {
    		$products_in_cart[ $key ] = $item['data']->get_title();
    	}
    	
    	$cart_contents = array();
    	foreach ( array_reverse($products_in_cart) as $cart_key => $product_title ) {
    		$cart_contents[ $cart_key ] = $woocommerce->cart->cart_contents[ $cart_key ];
    	}
    	$woocommerce->cart->cart_contents = $cart_contents;
    }, 100 );
    Thread Starter Wayn

    (@shnactor1)

    Thank You so much, it worked perfectly 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘reverse order of the cart’ is closed to new replies.