Skip to content

Commit

Permalink
NEW / Filter SQL in clean_order 'woo_cao_sql_req'. Allows you to adju…
Browse files Browse the repository at this point in the history
…st the SQL query before cleaning
  • Loading branch information
rvola committed Nov 26, 2018
1 parent 3a58d3b commit 4aed0ba
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions includes/class-cao.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,24 @@ public function check_order() {
$old_date = apply_filters( 'woo_cao_date_order', $old_date, $gateway, $mode );
$old_date_format = date( 'Y-m-d 00:00:00', $old_date );

$orders = $wpdb->get_results(
$wpdb->prepare(
"
SELECT posts.ID
FROM $wpdb->posts as posts
INNER JOIN $wpdb->postmeta as meta
ON posts.ID = meta.post_id
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'wc-on-hold'
AND posts.post_date < %s
AND meta.meta_key = '_payment_method'
AND meta.meta_value = %s
",
$old_date_format,
$gateway
)
// SQL - PREPARATION
$req = $wpdb->prepare( "
SELECT posts.ID
FROM $wpdb->posts as posts
INNER JOIN $wpdb->postmeta as meta
ON posts.ID = meta.post_id
WHERE posts.post_type = 'shop_order'
AND posts.post_status = 'wc-on-hold'
AND posts.post_date < %s
AND meta.meta_key = '_payment_method'
AND meta.meta_value = %s",
$old_date_format,
$gateway
);

$req = apply_filters( 'woo_cao_sql_req', $req, $gateway, $mode );

$orders = $wpdb->get_results( $req );
if ( $orders ) {
foreach ( $orders as $order ) {
// Cancel order.
Expand Down

0 comments on commit 4aed0ba

Please sign in to comment.