mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Do not render buttons on single product page if there is not subscription plan
This commit is contained in:
parent
d6c12ce29d
commit
c636192e98
3 changed files with 27 additions and 20 deletions
|
@ -21,25 +21,7 @@ class SingleProductActionHandler {
|
|||
this.cartHelper = null;
|
||||
}
|
||||
|
||||
getPlanIdFromVariation = (variation) => {
|
||||
let subscription_plan = '';
|
||||
PayPalCommerceGateway.variable_paypal_subscription_variations.forEach((element) => {
|
||||
let obj = {};
|
||||
variation.forEach(({name, value}) => {
|
||||
Object.assign(obj, {[name.replace('attribute_', '')]: value});
|
||||
})
|
||||
|
||||
if(JSON.stringify(obj) === JSON.stringify(element.attributes) && element.subscription_plan !== '') {
|
||||
subscription_plan = element.subscription_plan;
|
||||
}
|
||||
});
|
||||
|
||||
return subscription_plan;
|
||||
}
|
||||
|
||||
subscriptionsConfiguration(selected_variation = null) {
|
||||
const subscription_plan = selected_variation !== null ? this.getPlanIdFromVariation(selected_variation) : this.config.subscription_plan_id
|
||||
|
||||
subscriptionsConfiguration(subscription_plan) {
|
||||
return {
|
||||
createSubscription: (data, actions) => {
|
||||
return actions.subscription.create({
|
||||
|
|
|
@ -3,6 +3,7 @@ import SingleProductActionHandler from "../ActionHandler/SingleProductActionHand
|
|||
import {hide, show} from "../Helper/Hiding";
|
||||
import BootstrapHelper from "../Helper/BootstrapHelper";
|
||||
import {loadPaypalJsScript} from "../Helper/ScriptLoading";
|
||||
import {getPlanIdFromVariation} from "../Helper/Subscriptions"
|
||||
|
||||
class SingleProductBootstap {
|
||||
constructor(gateway, renderer, messages, errorHandler) {
|
||||
|
@ -165,6 +166,14 @@ class SingleProductBootstap {
|
|||
) {
|
||||
const buttonWrapper = document.getElementById('ppc-button-ppcp-gateway');
|
||||
buttonWrapper.innerHTML = '';
|
||||
|
||||
const subscription_plan = this.variations() !== null
|
||||
? getPlanIdFromVariation(this.variations())
|
||||
: PayPalCommerceGateway.subscription_plan_id
|
||||
if(!subscription_plan) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadPaypalJsScript(
|
||||
{
|
||||
clientId: PayPalCommerceGateway.client_id,
|
||||
|
@ -172,7 +181,7 @@ class SingleProductBootstap {
|
|||
intent: 'subscription',
|
||||
vault: true
|
||||
},
|
||||
actionHandler.subscriptionsConfiguration(this.variations()),
|
||||
actionHandler.subscriptionsConfiguration(subscription_plan),
|
||||
this.gateway.button.wrapper
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -2,3 +2,19 @@ export const isChangePaymentPage = () => {
|
|||
const urlParams = new URLSearchParams(window.location.search)
|
||||
return urlParams.has('change_payment_method');
|
||||
}
|
||||
|
||||
export const getPlanIdFromVariation = (variation) => {
|
||||
let subscription_plan = '';
|
||||
PayPalCommerceGateway.variable_paypal_subscription_variations.forEach((element) => {
|
||||
let obj = {};
|
||||
variation.forEach(({name, value}) => {
|
||||
Object.assign(obj, {[name.replace('attribute_', '')]: value});
|
||||
})
|
||||
|
||||
if(JSON.stringify(obj) === JSON.stringify(element.attributes) && element.subscription_plan !== '') {
|
||||
subscription_plan = element.subscription_plan;
|
||||
}
|
||||
});
|
||||
|
||||
return subscription_plan;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue