From 09c7537e48f14114d6d78397a0a070dfedc5cae4 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 16 Jun 2023 16:11:45 +0200 Subject: [PATCH] Hide non updatable form fields if subscription product connected to PayPal --- .../ContextBootstrap/SingleProductBootstap.js | 3 +++ .../resources/js/paypal-subscription.js | 16 ++++++++-------- .../src/FreeTrialHandlerTrait.php | 5 ++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js index 5c625b54e..7ee40db54 100644 --- a/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js +++ b/modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js @@ -91,6 +91,9 @@ class SingleProductBootstap { } priceAmountIsZero() { + if(subscriptionHasPlan()) { + return false; + } const price = this.priceAmount(); return !price || price === 0; } diff --git a/modules/ppcp-subscription/resources/js/paypal-subscription.js b/modules/ppcp-subscription/resources/js/paypal-subscription.js index bcf41a527..c42ca2597 100644 --- a/modules/ppcp-subscription/resources/js/paypal-subscription.js +++ b/modules/ppcp-subscription/resources/js/paypal-subscription.js @@ -8,18 +8,15 @@ document.addEventListener( const subscriptionPeriod = document.querySelector('#_subscription_period'); subscriptionPeriod.setAttribute('disabled', 'disabled'); - const subscriptionLength = document.querySelector('#_subscription_length'); - subscriptionLength.setAttribute('disabled', 'disabled'); + const subscriptionLength = document.querySelector('._subscription_length_field'); + subscriptionLength.style.display = 'none'; - const subscriptionTrialLength = document.querySelector('#_subscription_trial_length'); - subscriptionTrialLength.setAttribute('disabled', 'disabled'); - - const subscriptionTrialPeriod = document.querySelector('#_subscription_trial_period'); - subscriptionTrialPeriod.setAttribute('disabled', 'disabled'); + const subscriptionTrial = document.querySelector('._subscription_trial_length_field'); + subscriptionTrial.style.display = 'none'; } const unlinkBtn = document.getElementById('ppcp_unlink_sub_plan'); - unlinkBtn.addEventListener('click', (event)=>{ + unlinkBtn?.addEventListener('click', (event)=>{ event.preventDefault(); unlinkBtn.disabled = true; const spinner = document.getElementById('spinner-unlink-plan'); @@ -59,6 +56,9 @@ document.addEventListener( const planUnlinked = document.getElementById('pcpp-plan-unlinked'); planUnlinked.style.display = 'block'; + setTimeout(() => { + location.reload(); + }, 1000) }); }); }); diff --git a/modules/ppcp-subscription/src/FreeTrialHandlerTrait.php b/modules/ppcp-subscription/src/FreeTrialHandlerTrait.php index cbc6e02db..d528ff554 100644 --- a/modules/ppcp-subscription/src/FreeTrialHandlerTrait.php +++ b/modules/ppcp-subscription/src/FreeTrialHandlerTrait.php @@ -56,7 +56,10 @@ trait FreeTrialHandlerTrait { $product = wc_get_product(); - if ( ! $product || ! WC_Subscriptions_Product::is_subscription( $product ) ) { + if ( + ! $product || ! WC_Subscriptions_Product::is_subscription( $product ) + || $product->get_meta( '_ppcp_enable_subscription_product' ) === 'yes' + ) { return false; }