Skip to content

Commit

Permalink
Refine ECE availability check for Variable Subscriptions (#9897)
Browse files Browse the repository at this point in the history
  • Loading branch information
asumaran authored Dec 10, 2024
1 parent adbac29 commit 63376c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions changelog/as-fix-ece-variable-subs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Refine verification for disabling ECE on subscriptions that require shipping.
Original file line number Diff line number Diff line change
Expand Up @@ -760,22 +760,33 @@ private function is_product_supported() {
*
* @psalm-suppress UndefinedClass
*/
if ( is_null( $product )
|| ! is_object( $product )
|| ! in_array( $product->get_type(), $this->supported_product_types(), true )
|| ( class_exists( 'WC_Subscriptions_Product' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) // Trial subscriptions with shipping are not 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;

// Disable ECE for all variable subscriptions with free trials, as they are not currently supported. For now, ECE will be disabled for all such cases, and a solution will be addressed in a separate PR.
$is_free_trial_variable_sub = class_exists( 'WC_Subscriptions_Product' ) && $product->get_type() === 'variable-subscription' && WC_Subscriptions_Product::get_trial_length( $product ) > 0;

if (
! in_array( $product->get_type(), $this->supported_product_types(), true )
|| $is_free_trial_simple_subs
|| $is_free_trial_variable_sub
|| ( 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.
) {
$is_supported = false;
} elseif ( class_exists( 'WC_Product_Addons_Helper' ) ) {
// File upload addon not supported.
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() );
foreach ( $product_addons as $addon ) {
if ( 'file_upload' === $addon['type'] ) {
$is_supported = false;
break;
) {
$is_supported = false;
} elseif ( class_exists( 'WC_Product_Addons_Helper' ) ) {
// File upload addon not supported.
$product_addons = WC_Product_Addons_Helper::get_product_addons( $product->get_id() );
foreach ( $product_addons as $addon ) {
if ( 'file_upload' === $addon['type'] ) {
$is_supported = false;
break;
}
}
}
}
Expand Down

0 comments on commit 63376c3

Please sign in to comment.