• Resolved kognito

    (@kognito)


    Hi there,

    I’m looking for a way to put free samples and gift with purchases at the end of the invoice, possibly via sorting products by price?

    Many thanks for your help in advance!

    Best regards
    Clemens

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

    (@pomegranate)

    Hello Clemens,
    That’s certainly possible, with a small code snippet:

    
    add_filter( 'wpo_wcpdf_order_items_data', 'wpo_wcpdf_sort_items', 10, 2 );
    function wpo_wcpdf_sort_items ( $items, $order ) {
        usort($items, 'wpo_wcpdf_sort_by_price_desc');
        return $items;
    }
    
    function wpo_wcpdf_sort_by_price_desc($a, $b) {
        if ($a['item']['line_total']==$b['item']['line_total']) return 0;
        return ($a['item']['line_total']>$b['item']['line_total'])?-1:1;
    }
    

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

    Hope that helps!
    Ewout

    Thread Starter kognito

    (@kognito)

    Awesome, thanks so much for your help and the prompt reply!

    Just what I needed!

    Cheers
    Clemens

    Plugin Contributor Ewout

    (@pomegranate)

    You’re welcome Clemens! If you can spare a minute, I’d appreciate a plugin review!

    Ewout

    Thread Starter kognito

    (@kognito)

    Too easy! All done!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sort by price’ is closed to new replies.