• Resolved Ryan

    (@manovfaith)


    The customer wants products on the invoice separated by category with a line between the categories and the products in alphabetical order. Is this possible. If so, how? I have the products in alphabetical order with this code:

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

Viewing 1 replies (of 1 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hello Ryan,
    separating the products by category in the order details table will require you to create a custom template and add the necessary PHP loops for this, you will probably want separate tables for each category. You could first loop over the items and create a new array with all the items per category (i.e. $categorized_items => $category => $items ), and then loop over that array, applying the usort again.
    This is quite advanced and is unfortunately beyond what we can provide as free support.

    I hope the above gets you on track with this – good luck!
    Ewout

Viewing 1 replies (of 1 total)
  • The topic ‘Sort and Separate’ is closed to new replies.