Frequency: Customize Autoship Product Frequency Options
Note: Backwards compatibility supported for legacy custom frequency options display in 1.2.47 and forward.
Customize Autoship Frequency Options to include selections for the following frequency types:
- Days
- Weeks
- Months
- DayOfTheWeek
- DayOfTheMonth
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(); $options[] = 'Days-20' => array( 'frequency_type' => 'Days', 'frequency' => 20, 'display_name' => 'Every 20 Days' ), 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 );