mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +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' );
|
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 = () => {
|
const setupProducts = () => {
|
||||||
jQuery( '.wc_input_subscription_period' ).on( 'change', (e) => {
|
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_interval = e.target.parentElement.querySelector('select.wc_input_subscription_period_interval')?.value;
|
||||||
const period = e.target.value;
|
const period = e.target.value;
|
||||||
|
|
||||||
if (
|
checkSubscriptionPeriodsInterval(period, period_interval, linkBtn);
|
||||||
( 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');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery( '.wc_input_subscription_period_interval' ).on( 'change', (e) => {
|
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_interval = e.target.value;
|
||||||
const period = e.target.parentElement.querySelector('select.wc_input_subscription_period')?.value;
|
const period = e.target.parentElement.querySelector('select.wc_input_subscription_period')?.value;
|
||||||
|
|
||||||
if (
|
checkSubscriptionPeriodsInterval(period, period_interval, linkBtn);
|
||||||
( 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');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
PayPalCommerceGatewayPayPalSubscriptionProducts?.forEach(
|
PayPalCommerceGatewayPayPalSubscriptionProducts?.forEach(
|
||||||
|
|
|
@ -805,7 +805,6 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
|
||||||
echo sprintf(
|
echo sprintf(
|
||||||
// translators: %1$s and %2$s are button and wrapper html tags.
|
// translators: %1$s and %2$s are button and wrapper html tags.
|
||||||
esc_html__( '%1$sUnlink PayPal Subscription Plan%2$s', 'woocommerce-paypal-payments' ),
|
esc_html__( '%1$sUnlink PayPal Subscription Plan%2$s', 'woocommerce-paypal-payments' ),
|
||||||
//
|
|
||||||
'<p class="form-field ppcp-enable-subscription" id="ppcp-enable-subscription-' . esc_attr( (string) $product->get_id() ) . '" style="' . esc_attr( $display_unlink_p ) . '"><label></label><button class="button ppcp-unlink-sub-plan" id="ppcp-unlink-sub-plan-' . esc_attr( (string) $product->get_id() ) . '">',
|
'<p class="form-field ppcp-enable-subscription" id="ppcp-enable-subscription-' . esc_attr( (string) $product->get_id() ) . '" style="' . esc_attr( $display_unlink_p ) . '"><label></label><button class="button ppcp-unlink-sub-plan" id="ppcp-unlink-sub-plan-' . esc_attr( (string) $product->get_id() ) . '">',
|
||||||
'</button><span class="spinner is-active" id="spinner-unlink-plan" style="float: none; display:none;"></span></p>'
|
'</button><span class="spinner is-active" id="spinner-unlink-plan" style="float: none; display:none;"></span></p>'
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue