Show variations in same order
Show variations in same order as they displayed inside the product
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
//show variations in same order as they displayed inside the product add_filter( 'wpo_search_products_and_variations_results', function ( $result, $term ) { //set necessary values foreach ($result as &$item) { $item['menu_order'] = $item['product']->get_menu_order(); $item['parent_id'] = $item['product']->get_parent_id(); } usort( $result, function ( $a, $b ) { //default sorting for simple products if ($a['parent_id'] == 0 AND $b['parent_id'] == 0) { return strcmp( $a['sort'], $b['sort'] ); } //sort items inside one product if ($a['parent_id'] == $b['parent_id']) { return $a['menu_order'] < $b['menu_order'] ? -1 : 1; } //sort by parents return $a['parent_id'] > $b['parent_id'] ? -1 : 1; } ); return $result; }, 10, 2 ); |