Autoship Frequency Options Customization

Customize Autoship Frequency Options to include day-of-the-month, week, and monthly options.

Important: Always test customizations to your site on a staging environment before making changes to your live / production site.  If you are not experienced with testing changes on a staging site, here is a good article to review.

/**
* Set the frequency options to include Day of the Month, Week, and Monthly options.
* @param array $default_options The current drop down options.
* @param int $product_id The Simple or variation product id.
* @return array the filtered frequency options.
*/
function xx_override_frequency_options( $default_options, $product_id ){

  $options = array();
  for ( $i = 0, $f = 1; $i < 31; $i++, $f++ ) {
    $options[] = array(
      'frequency_type' => 'DayOfTheMonth',
      'frequency' => $f,
      'display_name' => autoship_get_frequency_display_name('DayOfTheMonth', $f )
    );
  }

  for ( $i = 0, $f = 1; $i < 4; $i++, $f++ ) {
    $options[] = array(
      'frequency_type' => 'Weeks',
      'frequency' => $f,
      'display_name' => autoship_get_frequency_display_name('Weeks', $f )
    );
  }

  for ( $i = 0, $f = 1; $i < 12; $i++, $f++ ) {
    $options[] = array(
      'frequency_type' => 'Months',
      'frequency' => $f,
      'display_name' => autoship_get_frequency_display_name('Months', $f )
    );
  }

  return $options;

}
add_filter( 'autoship-product-frequency-options', 'xx_override_frequency_options', 10, 2 );

Still need help? Contact Us Contact Us