diff --git a/includes/class-cao.php b/includes/class-cao.php index 74dfa75..63d42f4 100644 --- a/includes/class-cao.php +++ b/includes/class-cao.php @@ -105,8 +105,6 @@ public static function clean_cron() { */ public function check_order() { - global $wpdb; - if ( $this->gateways ) { foreach ( $this->gateways as $gateway ) { $options = get_option( 'woocommerce_' . $gateway . '_settings' ); @@ -133,25 +131,16 @@ public function check_order() { // Status to cancel $woo_status = $this->woo_status(); - $woo_status = implode( "','", $woo_status ); - - $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 IN ('$woo_status') - AND posts.post_date < %s - AND meta.meta_key = '_payment_method' - AND meta.meta_value = %s - ", - $old_date_format, - $gateway + + $orders = wc_get_orders( + array( + 'limit' => -1, + 'status' => $woo_status, + 'date_created' => '<' . $old_date_format, + 'payment_method' => $gateway, ) ); + if ( $orders ) { foreach ( $orders as $order ) { // Cancel order. diff --git a/includes/class-wp.php b/includes/class-wp.php index 768f88a..5475d23 100644 --- a/includes/class-wp.php +++ b/includes/class-wp.php @@ -33,6 +33,8 @@ public function __construct() { $this->load_languages(); add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); + add_action('before_woocommerce_init', array( $this, 'enable_woo_hpos' )); + $this->required(); new CAO(); @@ -92,4 +94,15 @@ public function plugin_row_meta( $plugin_meta, $plugin_file ) { return $plugin_meta; } + + /** + * Enable Woo HPOS ( High-performance order storage ) + * + * @return void + */ + public function enable_woo_hpos() { + if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); + } + } }