Native UI: Sort Product Selection Menu Alphabetically

(src/scheduled-orders.php) In this example a dev uses the autoship_filter_schedulable_products_data filter to sort their add product dropdown menu alphabetically. See how the menu is sorted alphabetically in the After image below?

Example

/**
 * Callback for uasort function, compares the value in two arrays
 *
 * @param array $a The first array
 * @param array $b The second array
 *
 * @return bool True if the title in first array is alphabetically after the second
 */
function xx_sort_by_title($a,$b){

    // Compare the title value - Could be any value in the array
    return $a["title"] > $b["title"];

}

/**
 * Sorts the Add Product drop down alphabetically by title on Native UI
 *
 * @param array $products The current products
 * @return array The filtered product list.
 */
function xx_filter_products( $products ){
  uasort($products,"xx_sort_by_title");
  return $products;
}
add_filter( 'autoship_filter_schedulable_products_data', 'xx_filter_products', 10, 1);

Before displays an unsorted list

After displays a sorted list