mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Merge pull request #704 from woocommerce/PCP-677-smart-button-not-visible-on-single-product-when-subscription-in-cart
Fix button_renderer logic & the behavior for single products
This commit is contained in:
commit
36874966b1
2 changed files with 44 additions and 47 deletions
|
@ -424,20 +424,22 @@ class SmartButton implements SmartButtonInterface {
|
|||
add_action(
|
||||
$this->single_product_renderer_hook(),
|
||||
function () {
|
||||
$product = wc_get_product();
|
||||
|
||||
if (
|
||||
is_a( $product, WC_Product::class )
|
||||
&& ! $this->product_supports_payment( $product )
|
||||
) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
},
|
||||
31
|
||||
);
|
||||
}
|
||||
|
||||
add_action(
|
||||
$this->pay_order_renderer_hook(),
|
||||
function (): void {
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( CardButtonGateway::ID );
|
||||
}
|
||||
);
|
||||
|
||||
$not_enabled_on_minicart = $this->settings->has( 'button_mini_cart_enabled' ) &&
|
||||
! $this->settings->get( 'button_mini_cart_enabled' );
|
||||
if (
|
||||
|
@ -464,27 +466,38 @@ class SmartButton implements SmartButtonInterface {
|
|||
);
|
||||
}
|
||||
|
||||
add_action(
|
||||
$this->checkout_button_renderer_hook(),
|
||||
function (): void {
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( CardButtonGateway::ID );
|
||||
}
|
||||
);
|
||||
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
$not_enabled_on_cart = $this->settings->has( 'button_cart_enabled' ) &&
|
||||
! $this->settings->get( 'button_cart_enabled' );
|
||||
add_action(
|
||||
$this->proceed_to_checkout_button_renderer_hook(),
|
||||
function() use ( $not_enabled_on_cart ) {
|
||||
if ( ! is_cart() || $not_enabled_on_cart || $this->is_free_trial_cart() || $this->is_cart_price_total_zero() ) {
|
||||
return;
|
||||
if ( isset( $available_gateways['ppcp-gateway'] ) ) {
|
||||
add_action(
|
||||
$this->pay_order_renderer_hook(),
|
||||
function (): void {
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( CardButtonGateway::ID );
|
||||
}
|
||||
);
|
||||
add_action(
|
||||
$this->checkout_button_renderer_hook(),
|
||||
function (): void {
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
$this->button_renderer( CardButtonGateway::ID );
|
||||
}
|
||||
);
|
||||
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
},
|
||||
20
|
||||
);
|
||||
$not_enabled_on_cart = $this->settings->has( 'button_cart_enabled' ) &&
|
||||
! $this->settings->get( 'button_cart_enabled' );
|
||||
add_action(
|
||||
$this->proceed_to_checkout_button_renderer_hook(),
|
||||
function() use ( $not_enabled_on_cart ) {
|
||||
if ( ! is_cart() || $not_enabled_on_cart || $this->is_free_trial_cart() || $this->is_cart_price_total_zero() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->button_renderer( PayPalGateway::ID );
|
||||
},
|
||||
20
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -546,22 +559,6 @@ class SmartButton implements SmartButtonInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
$product = wc_get_product();
|
||||
|
||||
if (
|
||||
! is_checkout() && is_a( $product, WC_Product::class )
|
||||
&& ! $this->product_supports_payment( $product )
|
||||
) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
if ( ! isset( $available_gateways[ $gateway_id ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The wrapper is needed for the loading spinner,
|
||||
// otherwise jQuery block() prevents buttons rendering.
|
||||
echo '<div class="ppc-button-wrapper"><div id="ppc-button-' . esc_attr( $gateway_id ) . '"></div></div>';
|
||||
|
@ -940,7 +937,9 @@ class SmartButton implements SmartButtonInterface {
|
|||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException If a setting was not found.
|
||||
*/
|
||||
private function url(): string {
|
||||
$intent = ( $this->settings->has( 'intent' ) ) ? $this->settings->get( 'intent' ) : 'capture';
|
||||
$intent = ( $this->settings->has( 'intent' ) ) ? $this->settings->get( 'intent' ) : 'capture';
|
||||
$product_intent = $this->subscription_helper->current_product_is_subscription() ? 'authorize' : $intent;
|
||||
$other_context_intent = $this->subscription_helper->cart_contains_subscription() ? 'authorize' : $intent;
|
||||
|
||||
$params = array(
|
||||
'client-id' => $this->client_id,
|
||||
|
@ -949,9 +948,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
'components' => implode( ',', $this->components() ),
|
||||
'vault' => $this->can_save_vault_token() ? 'true' : 'false',
|
||||
'commit' => is_checkout() ? 'true' : 'false',
|
||||
'intent' => ( $this->subscription_helper->cart_contains_subscription() || $this->subscription_helper->current_product_is_subscription() )
|
||||
? 'authorize'
|
||||
: $intent,
|
||||
'intent' => $this->context() === 'product' ? $product_intent : $other_context_intent,
|
||||
);
|
||||
if (
|
||||
$this->environment->current_environment_is( Environment::SANDBOX )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue