Fix button_renderer logic & the behavior for single products

This commit is contained in:
Narek Zakarian 2022-06-27 15:47:21 +04:00
parent b7226bf73e
commit 036e7d0c33

View file

@ -411,16 +411,23 @@ class SmartButton implements SmartButtonInterface {
) {
add_action(
$this->single_product_renderer_hook(),
array(
$this,
'button_renderer',
),
function () {
$product = wc_get_product();
if (
is_a( $product, WC_Product::class )
&& ! $this->product_supports_payment( $product )
) {
return;
}
$this->button_renderer();
},
31
);
}
add_action( $this->pay_order_renderer_hook(), array( $this, 'button_renderer' ), 10 );
$not_enabled_on_minicart = $this->settings->has( 'button_mini_cart_enabled' ) &&
! $this->settings->get( 'button_mini_cart_enabled' );
if (
@ -447,6 +454,10 @@ class SmartButton implements SmartButtonInterface {
);
}
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
if ( isset( $available_gateways['ppcp-gateway'] ) ) {
add_action( $this->pay_order_renderer_hook(), array( $this, 'button_renderer' ), 10 );
add_action( $this->checkout_button_renderer_hook(), array( $this, 'button_renderer' ), 10 );
$not_enabled_on_cart = $this->settings->has( 'button_cart_enabled' ) &&
@ -462,6 +473,7 @@ class SmartButton implements SmartButtonInterface {
},
20
);
}
return true;
}
@ -521,22 +533,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['ppcp-gateway'] ) ) {
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"></div></div>';