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

Enable ECE for shipping subscriptions with free trial and sign up fee #9955

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Enable ECE for shipping subscriptions with free trial and sign up fee.
10 changes: 5 additions & 5 deletions client/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +441 to +442
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well, but I wonder if adding more details to this comment here could help others understand the logic more quickly. I think linking to the PR makes sense, but just to provide additional context, not using as the main source of documentation.

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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.
Comment on lines +781 to +782
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

$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.
Expand Down
Loading