mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
load button component in JS sdk only when needed
This commit is contained in:
parent
a4aea53302
commit
cc4777273a
2 changed files with 44 additions and 8 deletions
|
@ -11,7 +11,7 @@ class Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderButtons(wrapper, contextConfig) {
|
renderButtons(wrapper, contextConfig) {
|
||||||
if (! document.querySelector(wrapper) || this.isAlreadyRendered(wrapper)) {
|
if (! document.querySelector(wrapper) || this.isAlreadyRendered(wrapper) || 'undefined' === typeof paypal.Buttons ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -312,12 +312,15 @@ class SmartButton implements SmartButtonInterface {
|
||||||
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
|
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
wp_enqueue_style(
|
|
||||||
'ppcp-hosted-fields',
|
if ( $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) ) {
|
||||||
$this->module_url . '/assets/css/hosted-fields.css',
|
wp_enqueue_style(
|
||||||
array(),
|
'ppcp-hosted-fields',
|
||||||
1
|
$this->module_url . '/assets/css/hosted-fields.css',
|
||||||
);
|
array(),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'ppcp-smart-button',
|
'ppcp-smart-button',
|
||||||
$this->module_url . '/assets/js/button.js',
|
$this->module_url . '/assets/js/button.js',
|
||||||
|
@ -732,7 +735,40 @@ class SmartButton implements SmartButtonInterface {
|
||||||
* @throws \Inpsyde\PayPalCommerce\WcGateway\Exception\NotFoundException If a setting was not found.
|
* @throws \Inpsyde\PayPalCommerce\WcGateway\Exception\NotFoundException If a setting was not found.
|
||||||
*/
|
*/
|
||||||
private function components(): array {
|
private function components(): array {
|
||||||
$components = array( 'buttons' );
|
$components = array();
|
||||||
|
|
||||||
|
$load_buttons = false;
|
||||||
|
if (
|
||||||
|
$this->context() === 'checkout'
|
||||||
|
&& $this->settings->has( 'button_enabled' )
|
||||||
|
&& $this->settings->get( 'button_enabled' )
|
||||||
|
) {
|
||||||
|
$load_buttons = true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$this->context() === 'product'
|
||||||
|
&& $this->settings->has( 'button_product_enabled' )
|
||||||
|
&& $this->settings->get( 'button_product_enabled' )
|
||||||
|
) {
|
||||||
|
$load_buttons = true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$this->context() === 'mini-cart'
|
||||||
|
&& $this->settings->has( 'button_mini-cart_enabled' )
|
||||||
|
&& $this->settings->get( 'button_mini-cart_enabled' )
|
||||||
|
) {
|
||||||
|
$load_buttons = true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$this->context() === 'cart'
|
||||||
|
&& $this->settings->has( 'button_cart_enabled' )
|
||||||
|
&& $this->settings->get( 'button_cart_enabled' )
|
||||||
|
) {
|
||||||
|
$load_buttons = true;
|
||||||
|
}
|
||||||
|
if ( $load_buttons ) {
|
||||||
|
$components[] = 'buttons';
|
||||||
|
}
|
||||||
if ( $this->messages_apply->for_country() ) {
|
if ( $this->messages_apply->for_country() ) {
|
||||||
$components[] = 'messages';
|
$components[] = 'messages';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue