Skip to content

Commit

Permalink
Enable ECE for shipping subscriptions with free trial and sign up fee
Browse files Browse the repository at this point in the history
  • Loading branch information
asumaran committed Dec 14, 2024
1 parent 009bc44 commit bb1ee4b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
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
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,12 @@ 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.
$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

0 comments on commit bb1ee4b

Please sign in to comment.