From 73999c5daf1bd6e39c5afb390a0084748ab017f5 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Tue, 21 Jul 2015 17:46:00 -0700 Subject: [PATCH] Simplify: Remove meta from resubscribe orders In Subscriptoins v2.0. Also deprecate the removal of it in 1.n, where resubscribe orders were called "parent renewal orders". --- ...s-gateway-simplify-commerce-deprecated.php | 18 +++++++++++ ...ss-wc-addons-gateway-simplify-commerce.php | 31 ++++++++----------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/includes/gateways/simplify-commerce-deprecated/class-wc-addons-gateway-simplify-commerce-deprecated.php b/includes/gateways/simplify-commerce-deprecated/class-wc-addons-gateway-simplify-commerce-deprecated.php index 3e0e5847888..aa5b1495ca9 100644 --- a/includes/gateways/simplify-commerce-deprecated/class-wc-addons-gateway-simplify-commerce-deprecated.php +++ b/includes/gateways/simplify-commerce-deprecated/class-wc-addons-gateway-simplify-commerce-deprecated.php @@ -24,6 +24,7 @@ class WC_Addons_Gateway_Simplify_Commerce_Deprecated extends WC_Addons_Gateway_S if ( class_exists( 'WC_Subscriptions_Order' ) ) { add_action( 'scheduled_subscription_payment_' . $this->id, array( $this, 'process_scheduled_subscription_payment' ), 10, 3 ); + add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'remove_renewal_order_meta' ), 10, 4 ); } } @@ -131,4 +132,21 @@ class WC_Addons_Gateway_Simplify_Commerce_Deprecated extends WC_Addons_Gateway_S WC_Subscriptions_Manager::process_subscription_payments_on_order( $order ); } } + + /** + * Don't transfer customer meta when creating a parent renewal order. + * + * @param string $order_meta_query MySQL query for pulling the metadata + * @param int $original_order_id Post ID of the order being used to purchased the subscription being renewed + * @param int $renewal_order_id Post ID of the order created for renewing the subscription + * @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child' + * @return string + */ + public function remove_renewal_order_meta( $order_meta_query, $original_order_id, $renewal_order_id, $new_order_role ) { + if ( 'parent' == $new_order_role ) { + $order_meta_query .= " AND `meta_key` NOT LIKE '_simplify_customer_id' "; + } + + return $order_meta_query; + } } diff --git a/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php b/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php index e3ce4642af4..78674d9b80a 100644 --- a/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php +++ b/includes/gateways/simplify-commerce/class-wc-addons-gateway-simplify-commerce.php @@ -24,9 +24,10 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce { if ( class_exists( 'WC_Subscriptions_Order' ) ) { add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); - add_filter( 'woocommerce_subscriptions_renewal_order_meta_query', array( $this, 'remove_renewal_order_meta' ), 10, 4 ); add_action( 'woocommerce_subscriptions_changed_failing_payment_method_' . $this->id, array( $this, 'update_failing_payment_method' ), 10, 3 ); + add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); + // Allow store managers to manually set Simplify as the payment method on a subscription add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); @@ -357,23 +358,6 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce { } } - /** - * Don't transfer customer meta when creating a parent renewal order. - * - * @param string $order_meta_query MySQL query for pulling the metadata - * @param int $original_order_id Post ID of the order being used to purchased the subscription being renewed - * @param int $renewal_order_id Post ID of the order created for renewing the subscription - * @param string $new_order_role The role the renewal order is taking, one of 'parent' or 'child' - * @return string - */ - public function remove_renewal_order_meta( $order_meta_query, $original_order_id, $renewal_order_id, $new_order_role ) { - if ( 'parent' == $new_order_role ) { - $order_meta_query .= " AND `meta_key` NOT LIKE '_simplify_customer_id' "; - } - - return $order_meta_query; - } - /** * Update the customer_id for a subscription after using Simplify to complete a payment to make up for * an automatic renewal payment which previously failed. @@ -428,6 +412,17 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce { } } + /** + * Don't transfer customer meta to resubscribe orders. + * + * @access public + * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription + * @return void + */ + public function delete_resubscribe_meta( $resubscribe_order ) { + delete_post_meta( $resubscribe_order->id, '_simplify_customer_id' ); + } + /** * Process a pre-order payment when the pre-order is released *