From cf68af182ce1161e0852f084d648864430aeb3b8 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 11 Oct 2024 13:58:25 +0200 Subject: [PATCH] Consider manual renewal and vaulting option when displaying buttons on product page --- .../ContextBootstrap/SingleProductBootstap.js | 14 +++++++++----- modules/ppcp-button/src/Assets/SmartButton.php | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js index a74214bd7..3bae016bf 100644 --- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js +++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js @@ -233,11 +233,15 @@ class SingleProductBootstap { this.form(), this.errorHandler ); - - if(!this.gateway.vaultingEnabled){ - return; - } - + if ( + ! this.gateway.vaultingEnabled && + [ 'subscription', 'variable-subscription' ].includes( + this.gateway.productType + ) && + this.gateway.manualRenewalEnabled !== '1' + ) { + return; + } if ( PayPalCommerceGateway.data_client_id.has_subscriptions && diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 5884ad317..a03d10198 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1318,8 +1318,21 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages 'should_handle_shipping_in_paypal' => $this->should_handle_shipping_in_paypal && ! $this->is_checkout(), 'needShipping' => $this->need_shipping(), 'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ), + 'productType' => null, + 'manualRenewalEnabled' => '', ); + if ( is_product() ) { + $product = wc_get_product( get_the_ID() ); + if ( is_a( $product, \WC_Product::class ) ) { + $localize['productType'] = $product->get_type(); + } + } + + if ( class_exists( '\WCS_Manual_Renewal_Manager' ) ) { + $localize['manualRenewalEnabled'] = \WCS_Manual_Renewal_Manager::is_manual_renewal_enabled(); + } + if ( 'pay-now' === $this->context() ) { $localize['pay_now'] = $this->pay_now_script_data(); }