//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 );
Show variations in same order as they displayed inside the product Print
Created by: Alex Prokaev
Modified on: Tue, 8 Oct, 2019 at 8:56 AM
Did you find it helpful? Yes No
Send feedbackSorry we couldn't be helpful. Help us improve this article with your feedback.