From b3c6d879c46f6992b129e460fbf39d9f91be7dc6 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Fri, 13 Dec 2024 19:11:43 -0500 Subject: [PATCH 1/2] Enable ECE for shipping subscriptions with free trial and sign up fee --- client/express-checkout/index.js | 10 +++++----- ...class-wc-payments-express-checkout-ajax-handler.php | 9 +++++---- ...lass-wc-payments-express-checkout-button-helper.php | 8 ++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/client/express-checkout/index.js b/client/express-checkout/index.js index 447f0c81198..239cafc68e4 100644 --- a/client/express-checkout/index.js +++ b/client/express-checkout/index.js @@ -437,13 +437,13 @@ jQuery( ( $ ) => { $.when( wcpayECE.getSelectedProductData() ) .then( ( response ) => { - // We do not support variable subscriptions with variations - // that require shipping and include a free trial. + // Disable ECE for shipping variable subscriptions with free trial and **no** sign up fee. + // Applies to Case 11 from matrix: + // https://github.com/Automattic/woocommerce-payments/issues/9771#issuecomment-2518829514 if ( - getExpressCheckoutData( 'product' ) - .product_type === 'variable-subscription' && response.needs_shipping && - response.has_free_trial + response.has_free_trial && + ! response.has_sign_up_fee ) { eceButton.destroy(); return; diff --git a/includes/express-checkout/class-wc-payments-express-checkout-ajax-handler.php b/includes/express-checkout/class-wc-payments-express-checkout-ajax-handler.php index d14460da71e..f0b60c08386 100644 --- a/includes/express-checkout/class-wc-payments-express-checkout-ajax-handler.php +++ b/includes/express-checkout/class-wc-payments-express-checkout-ajax-handler.php @@ -330,10 +330,11 @@ public function ajax_get_selected_product_data() { 'pending' => true, ]; - $data['needs_shipping'] = wc_shipping_enabled() && 0 !== wc_get_shipping_method_count( true ) && $product->needs_shipping(); - $data['currency'] = strtolower( get_woocommerce_currency() ); - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); - $data['has_free_trial'] = class_exists( 'WC_Subscriptions_Product' ) ? WC_Subscriptions_Product::get_trial_length( $product ) > 0 : false; + $data['needs_shipping'] = wc_shipping_enabled() && 0 !== wc_get_shipping_method_count( true ) && $product->needs_shipping(); + $data['currency'] = strtolower( get_woocommerce_currency() ); + $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); + $data['has_free_trial'] = class_exists( 'WC_Subscriptions_Product' ) ? WC_Subscriptions_Product::get_trial_length( $product ) > 0 : false; + $data['has_sign_up_fee'] = class_exists( 'WC_Subscriptions_Product' ) ? WC_Subscriptions_Product::get_sign_up_fee( $product ) > 0 : false; wp_send_json( $data ); } catch ( Exception $e ) { diff --git a/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php b/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php index 672f2584c67..ea512590f08 100644 --- a/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php +++ b/includes/express-checkout/class-wc-payments-express-checkout-button-helper.php @@ -742,7 +742,6 @@ public function get_product_data() { $data['needs_shipping'] = ( wc_shipping_enabled() && 0 !== wc_get_shipping_method_count( true ) && $product->needs_shipping() ); $data['currency'] = strtolower( $currency ); $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); - $data['product_type'] = $product->get_type(); return apply_filters( 'wcpay_payment_request_product_data', $data, $product ); } @@ -765,12 +764,13 @@ private function is_product_supported() { if ( is_null( $product ) || ! is_object( $product ) ) { $is_supported = false; } else { - // Simple subscription that needs shipping with free trials is not supported. - $is_free_trial_simple_subs = class_exists( 'WC_Subscriptions_Product' ) && $product->get_type() === 'subscription' && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0; + // Applies to case 3 from matrix: https://github.com/Automattic/woocommerce-payments/issues/9771#issuecomment-2518829514. + // Note: This does not check variable subscriptions, as that will be handled on the frontend. + $is_free_trial_simple_subs_no_sign_up_fee = class_exists( 'WC_Subscriptions_Product' ) && $product->get_type() === 'subscription' && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 && WC_Subscriptions_Product::get_sign_up_fee( $product ) === 0; if ( ! in_array( $product->get_type(), $this->supported_product_types(), true ) - || $is_free_trial_simple_subs + || $is_free_trial_simple_subs_no_sign_up_fee || ( class_exists( 'WC_Pre_Orders_Product' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) // Pre Orders charge upon release not supported. || ( class_exists( 'WC_Composite_Products' ) && $product->is_type( 'composite' ) ) // Composite products are not supported on the product page. || ( class_exists( 'WC_Mix_and_Match' ) && $product->is_type( 'mix-and-match' ) ) // Mix and match products are not supported on the product page. From b1f783f3632e71e68ecabe793eea4a14e12d64a1 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Fri, 13 Dec 2024 20:02:06 -0500 Subject: [PATCH 2/2] Add changelog entry --- .../as-fix-ece-shipping-subs-with-free-trial-and-sign-up-fee | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/as-fix-ece-shipping-subs-with-free-trial-and-sign-up-fee diff --git a/changelog/as-fix-ece-shipping-subs-with-free-trial-and-sign-up-fee b/changelog/as-fix-ece-shipping-subs-with-free-trial-and-sign-up-fee new file mode 100644 index 00000000000..3b479cc2d4b --- /dev/null +++ b/changelog/as-fix-ece-shipping-subs-with-free-trial-and-sign-up-fee @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Enable ECE for shipping subscriptions with free trial and sign up fee.