Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #17 #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: Woo HPOS Compatibility
  • Loading branch information
radosek committed May 16, 2024
commit 7b4bbc583a03446ec1115de67d6a5b1a2f1741e5
27 changes: 8 additions & 19 deletions includes/class-cao.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions includes/class-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_htop' ));

$this->required();

new CAO();
Expand Down Expand Up @@ -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_htop() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
}