Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pippinsplugins/6073235 to your computer and use it in GitHub Desktop.
Save pippinsplugins/6073235 to your computer and use it in GitHub Desktop.
Daily abandoned orders check
<?php
/*
* Plugin Name: Easy Digital Downloads - Daily Cron for Abandoned Payments
* Description: Checks for abandoned payments daily, instead of just weekly
* Author: Pippin Williamson
*/
/**
* Grab all pending payments older than one day
*
* @access public
* @return void
*/
function edd_mark_abandoned_orders_daily() {
$args = array(
'status' => 'pending',
'number' => -1,
'fields' => 'ids'
);
add_filter( 'posts_where', 'edd_custom_filter_where_older_than_day' );
$payments = edd_get_payments( $args );
remove_filter( 'posts_where', 'edd_custom_filter_where_older_than_day' );
if( $payments ) {
foreach( $payments as $payment ) {
edd_update_payment_status( $payment, 'abandoned' );
}
}
}
add_action( 'edd_daily_scheduled_events', 'edd_mark_abandoned_orders_daily' )
/**
* Filter where older than one day
*
* @access public
* @param string $where Where clause
* @return string $where Modified where clause
*/
function edd_custom_filter_where_older_than_day( $where = '' ) {
// Payments older than one day
$start = date( 'Y-m-d', strtotime( '-1 days' ) );
$where .= " AND post_date <= '{$start}'";
return $where;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment