sort items in woocommerce cart
-
hi
this is a brilliant piece of work. it displays all woocommerce products according to the sorting i do with this plugin. great!!!
but it does not sort the items added to cart. i actually need to sort those ordered products in customers and admin emails, they received after placing an order.i found this code from your website
add_filter(‘woocommerce_order_get_items’, ‘custom_woocommerce_order_get_items’, 10, 2);
function custom_woocommerce_order_get_items($items, $object)
{
//no need to reorder if less than 2 products
if(count($items) < 2)
return $items;//create a list of products within the order
$products = array();
foreach($items as $key => $item)
{
$products[ $item[‘product_id’] ] = $key;
}$sorted_items = array();
global $post;
$args = array(
‘posts_per_page’ => -1,
‘post_type’ => ‘product’,
‘orderby’ => ‘menu_order’,
‘order’ => ‘ASC’,
‘post__in’ => array_keys($products)
);
$custom_query = new WP_Query($args);
while($custom_query->have_posts())
{
$custom_query->the_post();
$sorted_items[ $products[$post->ID] ] = $items[ $products[$post->ID] ];
}//check for any left outside items
foreach($items as $key => $item)
{
if(isset($sorted_items[$key]))
$sorted_items[ $key ] = $item;
}return $sorted_items;
}
what i paste in function.php. it did a great job even without installing your plugin. it sorts all the products according to product orders. but sadly when i go to woocommerce> orders>
it shows this errorFatal error: Call to a member function get_formatted_billing_address() on a non-object in /home4/mrks7777/spicyaromabristol.co.uk/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php on line 672
n.b. it only disables me from watching the orders from woocommerce> orders>. otherwise all site working fine.
please help..thanks in advance
- The topic ‘sort items in woocommerce cart’ is closed to new replies.