Orders: Calculate Relative Next Occurrence for Day Next Week
Currently the Frequency Types for the Relative Next Occurrence Date is Days, Weeks, and Months. If you wanted to set certain products to process on a particular day next week, you would need to create a function that returns a date formatted for the autoship_calculate_relative_next_occurrence_date filter to use. This can be achieved in a number of ways. Below are examples of 2 different ways this can be done:
Anonymous Function
/** * Sets the Relative Next Occurrence * * @param string $date The relative next Occurrence date. * @param int $product_id The WC Product ID * @return string|NULL The date or null */ function xx_override_relative_next_occurrence( $date, $product_id ){ // create anonymous function that handles setting a day of the week for the following week // @param string $day unabbreviated name of the day $set_day_next_week = function($day){ // handle if day is capitalized, then format day to date formatted for filter strtolower($day); $to_process_day = date("m/d/Y H:i:s", strtotime($day . " next week")); return $to_process_day; }; // if prod = 9392 (beer tankard) set processing date to Wed next week if ($product_id == 9392){ return $date = $set_day_next_week("wednesday"); } // if prod = 9393 (beer fuel glass) set processing day to Thur next week elseif ($product_id == 9393) { return $date = $set_day_next_week("Thursday"); } return $date; } add_filter('autoship_calculate_relative_next_occurrence_date', 'xx_override_relative_next_occurrence', 10, 2 );
Assigning Date to an Object
/** * Sets the Relative Next Occurrence to next Wednesday for Roasted Coffee * and to next Thursday for Single Origin Club scheduled orders * * @param string $date The relative next Occurrence date. * @param int $product_id The WC Product ID * @return string|NULL The date or null */ function xx_override_relative_next_occurrence( $date, $product_id ){ $basedate = new DateTime(); // Roasted Coffee if ( '1133' == $product_id ) { $basedate->modify('next wednesday'); $date = $basedate->format("Y-m-d H:i:s"); } // Single Origin Club if ( '1332' == $product_id ) { $basedate->modify('next thursday'); $date = $basedate->format("Y-m-d H:i:s"); } return $date; } add_filter('autoship_calculate_relative_next_occurrence_date', 'xx_override_relative_next_occurrence', 10, 2 );