Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 10.2.0 - xxxx-xx-xx =
* Add - Support express checkout for free trial subscription products that require shipping
* Dev - Deprecates all the legacy checkout payment method classes
* Dev - Deprecates all the LPM class constants
* Dev - Remove all references to the UPE-enabled feature flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ public function is_invalid_subscription_product( $product, $is_product_page_requ
$needs_shipping = $product->needs_shipping();
$is_synced = WC_Subscriptions_Synchroniser::is_product_synced( $product );
$is_payment_upfront = WC_Subscriptions_Synchroniser::is_payment_upfront( $product );
$has_trial_period = WC_Subscriptions_Product::get_trial_length( $product ) > 0;

if ( $is_product_page_request && $is_synced && ! $is_payment_upfront && ! $needs_shipping ) {
/**
Expand All @@ -529,8 +528,6 @@ public function is_invalid_subscription_product( $product, $is_product_page_requ
continue;
} elseif ( $is_synced && ! $is_payment_upfront && $needs_shipping ) {
continue;
} elseif ( $has_trial_period && $needs_shipping ) {
continue;
} else {
// If we made it this far, the product is valid. Break out of the foreach and return early as we only care about invalid cases.
$is_invalid = false;
Expand Down Expand Up @@ -720,12 +717,6 @@ public function should_show_express_checkout_button() {
return false;
}

// Don't show in the product page if the product price is 0 and the product requires shipping.
if ( $is_product && $product && 0.0 === (float) $product->get_price() && $this->product_or_cart_needs_shipping() ) {
WC_Stripe_Logger::log( 'Stripe Express Checkout does not support free products that requires shipping.' );
return false;
}

if ( $is_product && $product && in_array( $product->get_type(), [ ProductType::VARIABLE, 'variable-subscription' ], true ) ) {
$stock_availability = array_column( $product->get_available_variations(), 'is_in_stock' );
// Don't show if all product variations are out-of-stock.
Expand Down Expand Up @@ -1379,6 +1370,11 @@ protected function calculate_shipping( $address = [] ) {
}
}

// Remove subscription shipping package filter if there is free trial in the cart to allow the calculation of shipping costs.
if ( class_exists( 'WC_Subscriptions_Cart' ) && WC_Subscriptions_Cart::cart_contains_free_trial() ) {
remove_filter( 'woocommerce_cart_shipping_packages', 'WC_Subscriptions_Cart::set_cart_shipping_packages', -10, 1 );
}

$packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages );

WC()->shipping->calculate_shipping( $packages );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 10.2.0 - xxxx-xx-xx =
* Add - Support express checkout for free trial subscription products that require shipping
* Dev - Deprecates all the legacy checkout payment method classes
* Dev - Deprecates all the LPM class constants
* Dev - Remove all references to the UPE-enabled feature flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,82 +309,6 @@ public function test_hides_ece_if_stripe_gateway_unavailable() {
WC()->payment_gateways()->payment_gateways = $original_gateways;
}

/**
* Test should_show_express_checkout_button, free trial logic.
*
* @return void
*/
public function test_hides_ece_if_free_trial_requires_shipping() {
$this->set_up_shipping_methods();

$mock_gateway = $this->getMockBuilder( WC_Stripe_UPE_Payment_Gateway::class )
->disableOriginalConstructor()
->getMock();

$wc_stripe_ece_helper_mock = $this->getMockBuilder( WC_Stripe_Express_Checkout_Helper::class )
->setConstructorArgs( [ $mock_gateway ] )
->onlyMethods( [ 'is_product', 'get_product', 'allowed_items_in_cart', 'should_show_ece_on_cart_page', 'should_show_ece_on_checkout_page' ] )
->getMock();

$wc_stripe_ece_helper_mock->method( 'is_product' )->willReturn( true );
$wc_stripe_ece_helper_mock->method( 'allowed_items_in_cart' )->willReturn( true );
$wc_stripe_ece_helper_mock->method( 'should_show_ece_on_cart_page' )->willReturn( true );
$wc_stripe_ece_helper_mock->method( 'should_show_ece_on_checkout_page' )->willReturn( true );
$wc_stripe_ece_helper_mock->testmode = true;

if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
define( 'WOOCOMMERCE_CHECKOUT', true );
}

// Ensure that the 'stripe' gateway is available.
$original_gateways = WC()->payment_gateways()->payment_gateways;
WC()->payment_gateways()->payment_gateways = [
'stripe' => new WC_Stripe_UPE_Payment_Gateway(),
];

update_option( 'woocommerce_calc_taxes', 'no' );

// Should show, as free virtual products does not require shipping.
$virtual_product = WC_Helper_Product::create_simple_product();
$virtual_product->set_virtual( true );
$virtual_product->set_tax_status( 'none' );
$virtual_product->set_price( 0 );
$virtual_product->save();

WC()->session->init();
WC()->cart->empty_cart();

WC()->cart->add_to_cart( $virtual_product->get_id(), 1 );
$wc_stripe_ece_helper_mock
->method( 'get_product' )
->willReturn( $virtual_product );

$this->assertTrue( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() );

// Should hide if the free product requires shipping.
$shippable_product = WC_Helper_Product::create_simple_product();
$shippable_product->set_virtual( false );
$shippable_product->set_tax_status( 'none' );
$shippable_product->save();

WC()->session->init();
WC()->cart->empty_cart();

WC()->cart->add_to_cart( $shippable_product->get_id(), 1 );
$wc_stripe_ece_helper_mock
->method( 'get_product' )
->willReturn( $shippable_product );

$this->assertFalse( $wc_stripe_ece_helper_mock->should_show_express_checkout_button() );

// Restore original settings.
WC()->cart->empty_cart();
WC()->session->cleanup_sessions();
WC()->payment_gateways()->payment_gateways = $original_gateways;

update_option( 'woocommerce_calc_taxes', 'yes' );
}

/**
* Test for get_checkout_data().
*/
Expand Down
Loading