Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. add_action( 'woocommerce_loaded', 'wc_custom_loaded' );
  2.  
  3. function wc_custom_loaded() {
  4. $old_statuses = array(
  5. 'failed',
  6. //uncomment any of the below statuses to include those statuses
  7. //'pending',
  8. //'processing',
  9. //'on-hold',
  10. //'cancelled',
  11. //'refunded'
  12. );
  13. foreach ( $old_statuses as $old_status ) {
  14. add_action( 'woocommerce_order_status_' . $old_status . '_to_completed', 'wc_custom_change_posted_date', 99, 1 );
  15. }
  16. }
  17.  
  18. function wc_custom_change_posted_date( $order_id ) {
  19. $order = wc_get_order( $order_id );
  20. $args = array(
  21. 'post_id' => $order_id,
  22. //wp_insert_post (called by wp_update_post) will set the date to "now" if `post_date` is empty, likewise with `post_date_gmt`
  23. 'post_date' => '',
  24. 'post_date_gmt' => '',
  25. );
  26. wp_update_post( $args );
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement