Created
July 1, 2021 15:34
-
-
Save marcomarkkez/403ce13f7e23ac03a47f8ef0b2197a31 to your computer and use it in GitHub Desktop.
Autocancelar órdenes en Woocommerce 3.2.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Cancela las ordenes que exceden 7 días en Woocommerce 3.2.2 esta es la única forma en la que funcionó | |
*/ | |
function autocancel_wc_orders(){ | |
$query = array( | |
'limit' => -1, /* Todas las órdenes */ | |
'status' => array('pending') | |
); | |
$orders = wc_get_orders( $query ); | |
foreach( $orders as $order ){ | |
$date = new DateTime( $order->get_date_created() ); | |
$today = new DateTime(); | |
$interval = $date->diff($today); | |
$datediff = $interval->format('%a'); | |
if( $datediff >= 7 ){// 7 días | |
$order->update_status('cancelled', 'Órden cancelada por 7 días sin pago'); | |
} | |
} | |
} | |
add_action( 'admin_init', 'autocancel_wc_orders' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment