mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
add js to not allow selecting not allowed period intervals
This commit is contained in:
parent
e67f4af9bf
commit
0f1750617f
1 changed files with 64 additions and 1 deletions
|
@ -68,12 +68,75 @@ document.addEventListener( 'DOMContentLoaded', () => {
|
|||
soldIndividually.setAttribute( 'disabled', 'disabled' );
|
||||
};
|
||||
|
||||
const updateInterval = () => {
|
||||
const subscriptionPeriodInterval = document.querySelector('#_subscription_period_interval');
|
||||
const subscriptionPeriod = document.querySelector('#_subscription_period');
|
||||
const subscriptionProduct = document.querySelector('#ppcp_enable_subscription_product');
|
||||
const optionsDisable = (start = 0) => {
|
||||
const subscriptionPeriodIntervalChildren = subscriptionPeriodInterval.children;
|
||||
for (let i = 0; i < subscriptionPeriodIntervalChildren.length; i++) {
|
||||
if ( start === 0 || parseInt( subscriptionPeriodIntervalChildren[i].value ) <= start ) {
|
||||
subscriptionPeriodIntervalChildren[i].disabled = false;
|
||||
subscriptionPeriodIntervalChildren[i].removeAttribute('disabled');
|
||||
} else {
|
||||
subscriptionPeriodIntervalChildren[i].disabled = true;
|
||||
subscriptionPeriodIntervalChildren[i].setAttribute('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
jQuery( '#_subscription_period_interval' ).trigger('change.select2');
|
||||
};
|
||||
|
||||
const updateSubscriptionPeriodInterval = () => {
|
||||
if (subscriptionProduct?.checked === false) {
|
||||
optionsDisable();
|
||||
return;
|
||||
}
|
||||
if ( subscriptionPeriod.value === 'year' ) {
|
||||
optionsDisable( 1 );
|
||||
if ( parseInt( subscriptionPeriodInterval.value ) > 1 ) {
|
||||
subscriptionPeriodInterval.value = '1';
|
||||
}
|
||||
}
|
||||
if ( subscriptionPeriod.value === 'month' ) {
|
||||
optionsDisable( 12 );
|
||||
if ( parseInt( subscriptionPeriodInterval.value ) > 12 ) {
|
||||
subscriptionPeriodInterval.value = '12';
|
||||
}
|
||||
}
|
||||
if ( subscriptionPeriod.value === 'week' ) {
|
||||
optionsDisable( 52 );
|
||||
if ( parseInt( subscriptionPeriodInterval.value ) > 52 ) {
|
||||
subscriptionPeriodInterval.value = '52';
|
||||
}
|
||||
}
|
||||
if ( subscriptionPeriod.value === 'day' ) {
|
||||
optionsDisable( 365 );
|
||||
if ( parseInt( subscriptionPeriodInterval.value ) > 365 ) {
|
||||
subscriptionPeriodInterval.value = '365';
|
||||
}
|
||||
}
|
||||
jQuery( '#_subscription_period_interval' ).trigger( 'change.select2' );
|
||||
}
|
||||
|
||||
subscriptionProduct?.addEventListener( 'change', (e) => {
|
||||
updateSubscriptionPeriodInterval();
|
||||
});
|
||||
jQuery( '#_subscription_period' ).on( 'change', (e) => {
|
||||
updateSubscriptionPeriodInterval();
|
||||
});
|
||||
jQuery( '#_subscription_period_interval' ).on( 'change', (e) => {
|
||||
updateSubscriptionPeriodInterval();
|
||||
});
|
||||
};
|
||||
|
||||
const setupProducts = () => {
|
||||
PayPalCommerceGatewayPayPalSubscriptionProducts?.forEach(
|
||||
( product ) => {
|
||||
if ( product.product_connected === 'yes' ) {
|
||||
disableFields( product.product_id );
|
||||
}
|
||||
} else {
|
||||
updateInterval();
|
||||
}
|
||||
|
||||
const unlinkBtn = document.getElementById(
|
||||
`ppcp-unlink-sub-plan-${ product.product_id }`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue