autoship_group_order_items (function)

( src/orders.php) Used to group and order items in the Cart or WooCommerce Order by Frequency, Frequency Type, and Next Occurrence. The Order items for Autoship are then upserted to QPilot. It takes $order_items and the (WooCommerce) $order as its parameter and returns the original order items sorted by Autoship values and with the non-Autoship selected items removed.

Function 

/**
* Groups and Orders the supplied order or cart items by Autoship Frequency,
* Autoship Type, and Autoship Next Occurrence.
* Order items included in an upsert to QPilot should be grouped by Autoship
*
* @param array $order_items.  The order or cart items to sort.
* @param WC_Order $order      Optional. The WC Order Object
* @return array               The original order items sorted by Autoship values.
*                             any non-autoship items are removed.
*/
function autoship_group_order_items( $order_items, $order = NULL ) {<p>  $order_items = apply_filters( 'autoship_group_order_items_data', $order_items, $order );</p><p>  $counter = 0;</p><p>  // Group frequencies
	$frequencies_hash = array();
	foreach ( $order_items as $item_key => $item ) {</p><p>		if ( !isset( $item['autoship_frequency_type'] ) || !isset( $item['autoship_frequency'] ) ||
          empty( $item['autoship_frequency_type'] ) || empty( $item['autoship_frequency'] ) )
       continue;</p><p>			$next_occurrence = ( ! empty( $item['autoship_next_occurrence'] ) ) ? $item['autoship_next_occurrence'] : '';
			$key = $item['autoship_frequency_type'] . ';' . $item['autoship_frequency'] . ';' . $next_occurrence;</p><p>  		$frequency_type = $item['autoship_frequency_type'];
  		$frequency = $item['autoship_frequency'];</p><p>    if ( isset( $frequencies_hash[ $key ] ) ){
      $frequencies_hash[ $key ][ 'items' ][$item_key] = $item;
    } else {</p><p>			$frequencies_hash[ $key ] = array(
  			'frequency_type' => $frequency_type,
  			'frequency' => $frequency,
  			'next_occurrence' => $next_occurrence,
  			'items' => array(
          $item_key => $item
        )
  		);
    }</p><p>	}</p><p>  ksort($frequencies_hash);
  return array_values($frequencies_hash);
}</p>