mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Check if pay for order contains subscription
This commit is contained in:
parent
21aa8980d6
commit
6d0c821b19
3 changed files with 33 additions and 5 deletions
|
@ -215,11 +215,12 @@ class SmartButton implements SmartButtonInterface {
|
|||
function ( array $default_fields, $id ) use ( $subscription_helper ) : array {
|
||||
if ( is_user_logged_in() && $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) && CreditCardGateway::ID === $id ) {
|
||||
|
||||
if ( ! $subscription_helper->cart_contains_subscription() ) {
|
||||
$default_fields['card-vault'] = sprintf(
|
||||
'<p class="form-row form-row-wide"><label for="vault"><input class="ppcp-credit-card-vault" type="checkbox" id="ppcp-credit-card-vault" name="vault">%s</label></p>',
|
||||
esc_html__( 'Save your Credit Card', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
if ( $subscription_helper->cart_contains_subscription() || $subscription_helper->order_pay_contains_subscription() ) {
|
||||
$default_fields['card-vault'] = '';
|
||||
}
|
||||
|
||||
$tokens = $this->payment_token_repository->all_for_user_id( get_current_user_id() );
|
||||
|
|
|
@ -55,6 +55,33 @@ class SubscriptionHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether pay for order contains subscriptions.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function order_pay_contains_subscription(): bool {
|
||||
if ( ! $this->plugin_is_active() || ! is_wc_endpoint_url( 'order-pay' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $wp;
|
||||
$order_id = (int) $wp->query_vars['order-pay'] ?? 0;
|
||||
if ( 0 === $order_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order( $order_id );
|
||||
foreach ( $order->get_items() as $item ) {
|
||||
$product = wc_get_product( $item->get_product_id() );
|
||||
if ( $product->get_type() === 'subscription' ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether only automatic payment gateways are accepted.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue