• Resolved Andrew Dixon

    (@aandrewdixon)


    Hi, is it possible to set the order the list of ordered items on the invoice and packing slip appear in. I have a specific field against my products that I would like to order it by but I’m having trouble seeing where the order of the list is set in the code. I think this might actually be a WooCommerce thing, as a I think the plugin is just getting the list from Woo, but if anyone can point me in the right direction of how I might change this, that would be really helpful.

    Thanks.

    Andrew.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hi @aandrewdixon

    Here’s an example to sort them by custom field:

    add_filter( 'wpo_wcpdf_order_items_data', 'wpo_wcpdf_order_items_data_sort_by_custom_field', 10, 3 );
    function wpo_wcpdf_order_items_data_sort_by_custom_field( $items, $order, $document_type )
    {
    uasort($items, function ($a, $b) {
    $cf_name = 'crop'; // custom field name
    $cf_a = $a['product']->get_meta($cf_name);
    $cf_b = $b['product']->get_meta($cf_name);
    return strnatcasecmp($cf_a, $cf_b);
    });
    return $items;
    }

    You can use the same hook to sort them however you prefer.

    Thread Starter Andrew Dixon

    (@aandrewdixon)

    Thanks @alexmigf I’ll give that a try.

    Thread Starter Andrew Dixon

    (@aandrewdixon)

    @alexmigf with a few tweaks I managed to get it working for my needs. Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Ordered Items order’ is closed to new replies.