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

    (@pomegranate)

    Sure, you can adapt the code from this thread, replacing ‘sku’ with ‘name’.

    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 (!isset($a['name'])) $a['name'] = '';
        if (!isset($b['name'])) $b['name'] = '';
        if ($a['name']==$b['name']) return 0;
        return ($a['name']<$b['name'])?-1:1;
    }

    Magic! ??

    Ewout

    Thread Starter Thane

    (@thanewest)

    Hey Ewout,
    Yeah that’s what I was thinking of trying, but I figured I should ask the pro before I made an attempt on my live site. It worked perfect, thanks again pal!

    -Thane

    Plugin Contributor Ewout

    (@pomegranate)

    Either way I wouldn’t make such an attempt on a live site.
    I recommend to make a copy of your site with Duplicator or the likes and use this as your staging/testing ground!

    Ewout

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sort Products Alphabetically’ is closed to new replies.