mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Disable variable subscription fields (WIP)
This commit is contained in:
parent
b066fc7ccf
commit
4ed7742d9a
2 changed files with 29 additions and 16 deletions
|
@ -1,9 +1,16 @@
|
|||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
const setupProducts = () => {
|
||||
PayPalCommerceGatewayPayPalSubscriptionProducts?.forEach((product) => {
|
||||
if(product.product_connected === 'yes') {
|
||||
const variations = document.querySelector('.woocommerce_variations');
|
||||
const disableFields = (productId) => {
|
||||
if(variations) {
|
||||
const children = variations.children;
|
||||
for(let i=0; i < children.length; i++) {
|
||||
const variableId = children[i].querySelector('h3').getElementsByClassName('variable_post_id')[0].value
|
||||
if( parseInt(variableId) === productId ) {
|
||||
children[i].querySelector('.woocommerce_variable_attributes').getElementsByClassName('wc_input_subscription_period_interval')[0].setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
const periodInterval = document.querySelector('#_subscription_period_interval');
|
||||
periodInterval.setAttribute('disabled', 'disabled');
|
||||
|
||||
|
@ -17,7 +24,13 @@ document.addEventListener(
|
|||
subscriptionTrial.style.display = 'none';
|
||||
}
|
||||
|
||||
const unlinkBtn = document.getElementById(`ppcp-unlink-sub-plan-${product.ajax.deactivate_plan.product_id}`);
|
||||
const setupProducts = () => {
|
||||
PayPalCommerceGatewayPayPalSubscriptionProducts?.forEach((product) => {
|
||||
if(product.product_connected === 'yes') {
|
||||
disableFields(product.product_id);
|
||||
}
|
||||
|
||||
const unlinkBtn = document.getElementById(`ppcp-unlink-sub-plan-${product.product_id}`);
|
||||
unlinkBtn?.addEventListener('click', (event)=>{
|
||||
event.preventDefault();
|
||||
unlinkBtn.disabled = true;
|
||||
|
@ -32,8 +45,8 @@ document.addEventListener(
|
|||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
nonce: product.ajax.deactivate_plan.nonce,
|
||||
plan_id: product.ajax.deactivate_plan.plan_id,
|
||||
product_id: product.ajax.deactivate_plan.product_id
|
||||
plan_id: product.plan_id,
|
||||
product_id: product.product_id
|
||||
})
|
||||
}).then(function (res) {
|
||||
return res.json();
|
||||
|
|
|
@ -954,12 +954,12 @@ class SubscriptionModule implements ModuleInterface {
|
|||
|
||||
return array(
|
||||
'product_connected' => $product->get_meta( '_ppcp_enable_subscription_product' ) ?? '',
|
||||
'plan_id' => $plan_id,
|
||||
'product_id' => $product->get_id(),
|
||||
'ajax' => array(
|
||||
'deactivate_plan' => array(
|
||||
'endpoint' => \WC_AJAX::get_endpoint( DeactivatePlanEndpoint::ENDPOINT ),
|
||||
'nonce' => wp_create_nonce( DeactivatePlanEndpoint::ENDPOINT ),
|
||||
'plan_id' => $plan_id,
|
||||
'product_id' => $product->get_id(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue