mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
moved js logic to function
This commit is contained in:
parent
5e85389830
commit
0131911f11
2 changed files with 20 additions and 29 deletions
|
@ -70,45 +70,37 @@ document.addEventListener( 'DOMContentLoaded', () => {
|
|||
soldIndividually.setAttribute( 'disabled', 'disabled' );
|
||||
};
|
||||
|
||||
const checkSubscriptionPeriodsInterval = (period, period_interval, linkBtn) => {
|
||||
if (
|
||||
( period === 'year' && parseInt( period_interval ) > 1 ) ||
|
||||
( period === 'month' && parseInt( period_interval ) > 12 ) ||
|
||||
( period === 'week' && parseInt( period_interval ) > 52 ) ||
|
||||
( period === 'day' && parseInt( period_interval ) > 356 )
|
||||
) {
|
||||
linkBtn.disabled = true;
|
||||
linkBtn.checked = false;
|
||||
linkBtn.setAttribute('title', __( 'Not allowed period intervall combination!', 'woocommerce-paypal-subscriptions' ) );
|
||||
} else {
|
||||
linkBtn.disabled = false;
|
||||
linkBtn.removeAttribute('title');
|
||||
}
|
||||
}
|
||||
|
||||
const setupProducts = () => {
|
||||
jQuery( '.wc_input_subscription_period' ).on( 'change', (e) => {
|
||||
const linkBtn = e.target.parentElement.parentElement.parentElement.parentElement.querySelector('input[name="_ppcp_enable_subscription_product"]');
|
||||
const linkBtn = e.target.parentElement.parentElement.parentElement.querySelector('input[name="_ppcp_enable_subscription_product"]');
|
||||
const period_interval = e.target.parentElement.querySelector('select.wc_input_subscription_period_interval')?.value;
|
||||
const period = e.target.value;
|
||||
|
||||
if (
|
||||
( period === 'year' && parseInt( period_interval ) > 1 ) ||
|
||||
( period === 'month' && parseInt( period_interval ) > 12 ) ||
|
||||
( period === 'week' && parseInt( period_interval ) > 52 ) ||
|
||||
( period === 'day' && parseInt( period_interval ) > 356 )
|
||||
) {
|
||||
linkBtn.disabled = true;
|
||||
linkBtn.checked = false;
|
||||
linkBtn.setAttribute('title', __( 'Not allowed period intervall combination!', 'woocommerce-paypal-subscriptions' ) );
|
||||
} else {
|
||||
linkBtn.disabled = false;
|
||||
linkBtn.removeAttribute('title');
|
||||
}
|
||||
checkSubscriptionPeriodsInterval(period, period_interval, linkBtn);
|
||||
});
|
||||
|
||||
jQuery( '.wc_input_subscription_period_interval' ).on( 'change', (e) => {
|
||||
const linkBtn = e.target.parentElement.parentElement.parentElement.parentElement.querySelector('input[name="_ppcp_enable_subscription_product"]');
|
||||
const linkBtn = e.target.parentElement.parentElement.parentElement.querySelector('input[name="_ppcp_enable_subscription_product"]');
|
||||
const period_interval = e.target.value;
|
||||
const period = e.target.parentElement.querySelector('select.wc_input_subscription_period')?.value;
|
||||
|
||||
if (
|
||||
( period === 'year' && parseInt( period_interval ) > 1 ) ||
|
||||
( period === 'month' && parseInt( period_interval ) > 12 ) ||
|
||||
( period === 'week' && parseInt( period_interval ) > 52 ) ||
|
||||
( period === 'day' && parseInt( period_interval ) > 356 )
|
||||
) {
|
||||
linkBtn.disabled = true;
|
||||
linkBtn.checked = false;
|
||||
linkBtn.setAttribute('title', __( 'Not allowed period intervall combination!', 'woocommerce-paypal-subscriptions' ) );
|
||||
} else {
|
||||
linkBtn.disabled = false;
|
||||
linkBtn.removeAttribute('title');
|
||||
}
|
||||
checkSubscriptionPeriodsInterval(period, period_interval, linkBtn);
|
||||
});
|
||||
|
||||
PayPalCommerceGatewayPayPalSubscriptionProducts?.forEach(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue