mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Disable save to account checkout if subscription in the cart
This commit is contained in:
parent
cd8cfaf0b8
commit
51aa79af11
4 changed files with 29 additions and 12 deletions
|
@ -112,6 +112,14 @@ class CardFieldsRenderer {
|
|||
|
||||
show(buttonSelector);
|
||||
|
||||
if(this.defaultConfig.cart_contains_subscription) {
|
||||
const saveToAccount = document.querySelector('#wc-ppcp-credit-card-gateway-new-payment-method');
|
||||
if(saveToAccount) {
|
||||
saveToAccount.checked = true;
|
||||
saveToAccount.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector(buttonSelector).addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
this.spinner.block();
|
||||
|
|
|
@ -1056,6 +1056,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
'endpoint' => \WC_AJAX::get_endpoint( CartScriptParamsEndpoint::ENDPOINT ),
|
||||
),
|
||||
),
|
||||
'cart_contains_subscription' => $this->subscription_helper->cart_contains_subscription(),
|
||||
'subscription_plan_id' => $this->subscription_helper->paypal_subscription_id(),
|
||||
'variable_paypal_subscription_variations' => $this->subscription_helper->variable_paypal_subscription_variations(),
|
||||
'subscription_product_allowed' => $this->subscription_helper->checkout_subscription_product_allowed(),
|
||||
|
|
|
@ -28,6 +28,14 @@ document.addEventListener(
|
|||
init()
|
||||
});
|
||||
|
||||
if(ppcp_add_payment_method.is_subscription_change_payment_page) {
|
||||
const saveToAccount = document.querySelector('#wc-ppcp-credit-card-gateway-new-payment-method');
|
||||
if(saveToAccount) {
|
||||
saveToAccount.checked = true;
|
||||
saveToAccount.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
loadScript({
|
||||
clientId: ppcp_add_payment_method.client_id,
|
||||
|
|
|
@ -152,8 +152,11 @@ class WcSubscriptionsModule implements ModuleInterface {
|
|||
|
||||
add_filter(
|
||||
'woocommerce_available_payment_gateways',
|
||||
function( array $methods ): array {
|
||||
if ( ! is_wc_endpoint_url( 'order-pay' ) ) {
|
||||
function( array $methods ) use ( $c ) : array {
|
||||
if (
|
||||
! is_wc_endpoint_url( 'order-pay' )
|
||||
|| $c->has( 'save-payment-methods.eligible' ) && $c->get( 'save-payment-methods.eligible' )
|
||||
) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
|
@ -261,18 +264,15 @@ class WcSubscriptionsModule implements ModuleInterface {
|
|||
&& $subscription_helper->is_subscription_change_payment()
|
||||
) {
|
||||
$tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id(), PayPalGateway::ID );
|
||||
$output = sprintf(
|
||||
'<p class="form-row form-row-wide"><label>%1$s</label><select id="saved-paypal-payment" name="saved_paypal_payment">',
|
||||
esc_html__( 'Select PayPal payment', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
|
||||
$output = '<ul class="wc-saved-payment-methods">';
|
||||
foreach ( $tokens as $token ) {
|
||||
$output .= sprintf(
|
||||
'<option value="%1$s">%2$s</option>',
|
||||
$token->get_id(),
|
||||
$token->get_meta( 'email' ) ?? ''
|
||||
);
|
||||
$output .= '<li>';
|
||||
$output .= sprintf( '<input name="saved_paypal_payment" type="radio" value="%s" style="width:auto;" checked="checked">', $token->get_id() );
|
||||
$output .= sprintf( '<label for="saved_paypal_payment">%s</label>', $token->get_meta( 'email' ) ?? '' );
|
||||
$output .= '</li>';
|
||||
}
|
||||
$output .= '</select></p>';
|
||||
$output .= '</ul>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue