From c701b46a40c40a04039a7c2d98a3b6552c17e735 Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 12 Apr 2022 15:00:11 +0300 Subject: [PATCH] Remove paypal buttons for free trial everywhere except checkout --- modules/ppcp-button/resources/js/button.js | 2 +- modules/ppcp-button/src/Assets/SmartButton.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js index d92b86707..dc831b6dc 100644 --- a/modules/ppcp-button/resources/js/button.js +++ b/modules/ppcp-button/resources/js/button.js @@ -122,7 +122,7 @@ document.addEventListener( if ( !['checkout', 'pay-now'].includes(PayPalCommerceGateway.context) || isChangePaymentPage() - || (PayPalCommerceGateway.is_free_trial_cart && vaulted_paypal_email !== '') + || (PayPalCommerceGateway.is_free_trial_cart && PayPalCommerceGateway.vaulted_paypal_email !== '') ) { return; } diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 08a7e370d..4824404ef 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -397,6 +397,9 @@ class SmartButton implements SmartButtonInterface { if ( ( is_product() || wc_post_content_has_shortcode( 'product_page' ) ) && ! $not_enabled_on_product_page + // TODO: it seems like there is no easy way to properly handle vaulted PayPal free trial, + // so disable the buttons for now everywhere except checkout for free trial. + && ! $this->is_free_trial_product() ) { add_action( $this->single_product_renderer_hook(), @@ -414,11 +417,12 @@ class SmartButton implements SmartButtonInterface { ! $this->settings->get( 'button_mini_cart_enabled' ); if ( ! $not_enabled_on_minicart + && ! $this->is_free_trial_cart() ) { add_action( $this->mini_cart_button_renderer_hook(), function () { - if ( $this->is_cart_price_total_zero() ) { + if ( $this->is_cart_price_total_zero() && ! $this->is_free_trial_cart() ) { return; } @@ -431,7 +435,7 @@ class SmartButton implements SmartButtonInterface { ); } - if ( $this->is_cart_price_total_zero() ) { + if ( $this->is_cart_price_total_zero() && ! $this->is_free_trial_cart() ) { return false; } @@ -440,6 +444,7 @@ class SmartButton implements SmartButtonInterface { if ( is_cart() && ! $not_enabled_on_cart + && ! $this->is_free_trial_cart() ) { add_action( $this->proceed_to_checkout_button_renderer_hook(),