Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_loaded', 'wc_custom_loaded' );
- function wc_custom_loaded() {
- $old_statuses = array(
- 'failed',
- //uncomment any of the below statuses to include those statuses
- //'pending',
- //'processing',
- //'on-hold',
- //'cancelled',
- //'refunded'
- );
- foreach ( $old_statuses as $old_status ) {
- add_action( 'woocommerce_order_status_' . $old_status . '_to_completed', 'wc_custom_change_posted_date', 99, 1 );
- }
- }
- function wc_custom_change_posted_date( $order_id ) {
- $order = wc_get_order( $order_id );
- $args = array(
- 'post_id' => $order_id,
- //wp_insert_post (called by wp_update_post) will set the date to "now" if `post_date` is empty, likewise with `post_date_gmt`
- 'post_date' => '',
- 'post_date_gmt' => '',
- );
- wp_update_post( $args );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement