{"id":7470,"date":"2021-09-05T23:50:31","date_gmt":"2021-09-06T06:50:31","guid":{"rendered":"https:\/\/codedcommerce.com\/?post_type=product&#038;p=7470"},"modified":"2023-10-08T19:40:08","modified_gmt":"2023-10-09T02:40:08","slug":"modify-cart-items-sort-order","status":"publish","type":"woo-code","link":"https:\/\/codedcommerce.com\/woo\/modify-cart-items-sort-order\/","title":{"rendered":"Modify cart items sort order"},"content":{"rendered":"\n<pre class=\"wp-block-code language-php\"><code>\/\/ Sort Cart Items\nadd_action( 'woocommerce_cart_loaded_from_session', function() {\n\n\t\/\/ Get Cart Items\n\t$cart_items = WC()->cart->get_cart_contents();\n\n\t\/\/ Only For Two Plus\n\tif( count( $cart_items ) &lt; 2 ) {\n\t\treturn;\n\t}\n\n\t\/\/ Get Sorting BY Job And Room\n\t$sorting = &#91;];\n\tforeach( $cart_items as $item_id => $item ) {\n\t\t$sorting&#91;] = wc_get_order_item_meta(\n\t\t\t$item_id, 'CustomFieldName', true\n\t\t);\n\t}\n\tarray_multisort( $locations, SORT_ASC, $sorting );\n\n\t\/\/ Apply To Cart Session\n\tWC()->cart->cart_contents = $cart_items;\n\n} );\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-7470","woo-code","type-woo-code","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/woo-code\/7470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/woo-code"}],"about":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/types\/woo-code"}],"wp:attachment":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/media?parent=7470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}