autoship_create_scheduled_order_next_occurrence

(src > orders.php) Inside the autoship_get_scheduled_order_data function, and an be used to modify the next_occurence date for each order. The filter takes the 1. next_occurrence, 2. frequency_type, 3. frequency, 4. creation_date, and 5. WC Order object as parameters and expects a return value in 'Y-m-d H:i:s' format.

Example

/**
 * Globally change Scheduled Orders' next occurrence date to a Monday if date falls on a Sat or Sun
 *
 * @param string       $next_occurrence The current assigned next occurrence date
 * @param string       $frequency_type. The frequency type assigned to this product
 * @param int          $frequency.      The actual frequency duration.
 * @param string       $creation_date   The creation date for the order.
 *                                      Date should be in Y-m-d H:i:s format ( 2019-07-19 15:21:39 )
 * @return string The filtered next occurrence date should be in Y-m-d\TH:i:s format.
 */
function xx_change_next_occurrence_date ($next_occurrence, $frequency_type, $frequency, $creation_date, $wc_order){

  // Call the API to get the calculated next occurrence date based off creation.
  $calculated_date = autoship_calculate_scheduled_order_next_occurrence ( $frequency_type, $frequency, $creation_date );

  // Check for API errors.
  if ( is_wp_error( $calculated_date ) )
  return $next_occurrence;

  // Get the day for the current date time string.
  $day = date("D", strtotime( $calculated_date ));

  // if day is Sat add 2 days to next occurrence
  // else if day is Sun add 1 day to next occurrence
  if ( $day == 'Sat' ){
    $next_occurrence = date("Y-m-d\TH:i:s", strtotime( $calculated_date ) + 172800);
  } else if ( $day == 'Sun' ){
    $next_occurrence = date("Y-m-d\TH:i:s", strtotime( $calculated_date ) + 86400);
  }

  return $next_occurrence;

}
add_filter('autoship_create_scheduled_order_next_occurrence', 'xx_change_next_occurrence_date', 10, 5);