Skip to content

Allow purchase of free trials with ECE #4557

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

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
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 ***

= 9.9.0 - xxxx-xx-xx =
* Add - Allow the purchase of free trials using the Express Payment methods when the product does not require shipping
* Fix - Payment method test instructions not showing up for the Optimized Checkout payment element
* Add - Includes a new notice to highlight the Optimized Checkout feature above the payment methods list in the Stripe settings page
* Update - Increases the default font size for the Optimized Checkout payment element to match the rest of the checkout form
Expand Down
4 changes: 1 addition & 3 deletions client/blocks/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ const expressCheckoutElement = ( expressPaymentMethod, api ) => {
);
const edit = getEditorElement( expressPaymentMethod );
const canMakePayment = ( { cart } ) => {
if ( parseFloat( cart.cartTotals.total_price ) === 0.0 ) {
return false;
}
return true;

if ( ! getBlocksConfiguration()?.shouldShowExpressCheckoutButton ) {
return false;
Expand Down
1 change: 0 additions & 1 deletion client/express-checkout/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export const getExpressCheckoutButtonAppearance = () => {
return {
variables: {
borderRadius: `${
getExpressCheckoutData( 'button' )?.radius ||
getDefaultBorderRadius()
}px`,
spacingUnit: '6px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ public function is_page_supported() {
* @return boolean True if express checkout elements are supported on current page, false otherwise
*/
public function should_show_express_checkout_button() {
return true;

// Bail if account is not connected.
if ( ! WC_Stripe::get_instance()->connect->is_connected() ) {
WC_Stripe_Logger::log( 'Account is not connected.' );
Expand Down Expand Up @@ -685,10 +687,9 @@ public function should_show_express_checkout_button() {
return false;
}

// Don't show in the product page if the product price is 0.
// ToDo: support free trials. Free trials should be supported if the product does not require shipping.
if ( $is_product && $product && 0.0 === (float) $product->get_price() ) {
WC_Stripe_Logger::log( 'Stripe Express Checkout does not support free products.' );
// 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;
}

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 ==

= 9.9.0 - xxxx-xx-xx =
* Add - Allow the purchase of free trials using the Express Payment methods when the product does not require shipping
* Fix - Payment method test instructions not showing up for the Optimized Checkout payment element
* Add - Includes a new notice to highlight the Optimized Checkout feature above the payment methods list in the Stripe settings page
* Update - Increases the default font size for the Optimized Checkout payment element to match the rest of the checkout form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,86 @@ 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();

$wc_stripe_ece_helper_mock = $this->createPartialMock(
WC_Stripe_Express_Checkout_Helper::class,
[
'is_product',
'get_product',
'allowed_items_in_cart',
'should_show_ece_on_cart_page',
'should_show_ece_on_checkout_page',
],
);

$wc_stripe_ece_helper_mock->expects( $this->any() )->method( 'is_product' )->willReturn( true );
$wc_stripe_ece_helper_mock->expects( $this->any() )->method( 'allowed_items_in_cart' )->willReturn( true );
$wc_stripe_ece_helper_mock->expects( $this->any() )->method( 'should_show_ece_on_cart_page' )->willReturn( true );
$wc_stripe_ece_helper_mock->expects( $this->any() )->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_Gateway_Stripe(),
];

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
->expects( $this->any() )
->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
->expects( $this->any() )
->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