Created
July 24, 2013 18:38
-
-
Save pippinsplugins/6073235 to your computer and use it in GitHub Desktop.
Daily abandoned orders check
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
<?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