• Resolved fabiogloor

    (@fabiogloor)


    I am trying to sort the products alphabetically. Is this possible? It seems that currently the items are sorted by time they added to cart. Is that correct? Thx in advance for the help.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi!
    That’s correct – by default WooCommerce sorts the products in the order in which they were added to the cart (in emails, order backend, and this is also how PDF Invoices receives the item data).

    To sort the products in the invoice by name, you can use this code snippet:

    
    add_filter( 'wpo_wcpdf_order_items_data', 'wpo_wcpdf_sort_items_by_name', 10, 2 );
    function wpo_wcpdf_sort_items_by_name ( $items, $order ) {
    	usort($items, 'wpo_wcpdf_sort_by_name');
    	return $items;
    }
    
    function wpo_wcpdf_sort_by_name($a, $b) {
    	if ($a['name']==$b['name']) return 0;
    	return ($a['name']<$b['name'])?-1:1;
    }
    

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Happy New Year!
    Ewout

    Hi,
    is it possibile to sort item for:
    alphabetic order
    and after for attribute alphabetic order

    for example:
    Tshirt A size: L
    Tshirt A size: M
    Tshirt A size: S
    Tshirt B size: M
    Tshirt B size: S

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sort Product-Items Alphabetical’ is closed to new replies.