mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Validate subscription price in PayPal Subscriptions logic. Check Interval on page load
This commit is contained in:
parent
f068ac1b3c
commit
031b50264c
1 changed files with 25 additions and 5 deletions
|
@ -70,16 +70,22 @@ document.addEventListener( 'DOMContentLoaded', () => {
|
|||
soldIndividually.setAttribute( 'disabled', 'disabled' );
|
||||
};
|
||||
|
||||
const checkSubscriptionPeriodsInterval = (period, period_interval, linkBtn) => {
|
||||
const checkSubscriptionPeriodsInterval = (period, period_interval, price, 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 )
|
||||
( period === 'day' && parseInt( period_interval ) > 356 ) ||
|
||||
( ! price || parseInt( price ) < 0)
|
||||
) {
|
||||
linkBtn.disabled = true;
|
||||
linkBtn.checked = false;
|
||||
linkBtn.setAttribute('title', __( 'Not allowed period intervall combination for PayPal Subscriptions!', 'woocommerce-paypal-subscriptions' ) );
|
||||
if (! price || parseInt( price ) < 0 ) {
|
||||
linkBtn.setAttribute('title', __( '0 Price not allowed for PayPal Subscriptions!', 'woocommerce-paypal-subscriptions' ) );
|
||||
} else {
|
||||
linkBtn.setAttribute('title', __( 'Not allowed period intervall combination for PayPal Subscriptions!', 'woocommerce-paypal-subscriptions' ) );
|
||||
}
|
||||
|
||||
} else {
|
||||
linkBtn.disabled = false;
|
||||
linkBtn.removeAttribute('title');
|
||||
|
@ -91,18 +97,32 @@ document.addEventListener( 'DOMContentLoaded', () => {
|
|||
const linkBtn = e.target.parentElement.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;
|
||||
const price = e.target.value;
|
||||
|
||||
checkSubscriptionPeriodsInterval(period, period_interval, linkBtn);
|
||||
checkSubscriptionPeriodsInterval(period, period_interval, price, 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 period_interval = e.target.value;
|
||||
const period = e.target.parentElement.querySelector('select.wc_input_subscription_period')?.value;
|
||||
const price = e.target.value;
|
||||
|
||||
checkSubscriptionPeriodsInterval(period, period_interval, linkBtn);
|
||||
checkSubscriptionPeriodsInterval(period, period_interval, price, linkBtn);
|
||||
});
|
||||
|
||||
jQuery( '.wc_input_subscription_price' ).on( 'change', (e) => {
|
||||
const linkBtn = e.target.parentElement.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.parentElement.querySelector('select.wc_input_subscription_period')?.value;
|
||||
const price = e.target.value;
|
||||
|
||||
checkSubscriptionPeriodsInterval(period, period_interval, price, linkBtn);
|
||||
});
|
||||
|
||||
jQuery( '.wc_input_subscription_price' ).trigger( 'change' );
|
||||
|
||||
|
||||
PayPalCommerceGatewayPayPalSubscriptionProducts?.forEach(
|
||||
( product ) => {
|
||||
if ( product.product_connected === 'yes' ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue