Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Cancela o pedido pendende depois de algum tempo
- */
- function cancel_pending_order_after_x_days() {
- $limit = 4;
- global $wpdb;
- $expired_payment_orders = $wpdb->get_col($wpdb->prepare("
- SELECT posts.ID
- FROM {$wpdb->posts} AS posts
- WHERE posts.post_status = 'wc-pending'
- AND posts.post_date < %s
- ", date('Y-m-d H:i:s', strtotime('-' . $limit . ' days'))));
- if ($expired_payment_orders) {
- foreach ($expired_payment_orders as $order) {
- $order = wc_get_order($order);
- $order->update_status('cancelled', 'Pedido foi expirado.');
- }
- }
- }
- // Agenda a verificação
- function init_cancel_pending_order_after_x_days() {
- if (!wp_next_scheduled('schedule_cancel_pending_order_after_x_days')) {
- wp_schedule_event(time(), 'daily', 'schedule_cancel_pending_order_after_x_days');
- }
- }
- add_action('init', 'init_cancel_pending_order_after_x_days');
- // Excecuta a verificação
- add_action('schedule_cancel_pending_order_after_x_days', 'cancel_pending_order_after_x_days');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement