Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. /**
  2. * Alters the Next Occurrence Date for a Scheduled Order based on custom field.
  3. * @param array $scheduled_order_data The Scheduled Order Data to be sent to API.
  4. * @param int The current WC Order ID.
  5. * @return array The filtered Scheduled Order Data.
  6. */
  7. function xx_adjust_next_scheduled_order_date( $scheduled_order_data, $order_id ){
  8.  
  9. // Make some call to check the custom Datepicker field & then convert to UTC
  10. // Date Time String.
  11. $value = get_post_meta( $order_id, 'xx_custom_date_picker_field' );
  12.  
  13. // Adjust the NextOccurrenceUtc to match the custom value.
  14. // Get the Date into the Date Time String the API expects
  15. $order_date = new WC_DateTime( $value );
  16. $scheduled_order_data['NextOccurrenceUtc'] = $order_date->format('Y-m-d\TH:i:s');
  17.  
  18. return $scheduled_order_data;
  19.  
  20. }
  21. add_filter( 'autoship_create_scheduled_order_data', 'xx_adjust_next_scheduled_order_date', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement