mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Refactor styles loading on GooglePay and ApplePay
Remove unnecessary console.log on GooglePay and ApplePay
This commit is contained in:
parent
567a7a2065
commit
b11a539c24
6 changed files with 56 additions and 21 deletions
|
@ -20,7 +20,6 @@ import ApplepayManager from "./ApplepayManager";
|
||||||
(typeof (buttonConfig) === 'undefined') ||
|
(typeof (buttonConfig) === 'undefined') ||
|
||||||
(typeof (ppcpConfig) === 'undefined')
|
(typeof (ppcpConfig) === 'undefined')
|
||||||
) {
|
) {
|
||||||
console.error('PayPal button could not be configured.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const isMiniCart = ppcpConfig.mini_cart_buttons_enabled;
|
const isMiniCart = ppcpConfig.mini_cart_buttons_enabled;
|
||||||
|
|
|
@ -136,10 +136,18 @@ class ApplepayModule implements ModuleInterface {
|
||||||
assert( $button instanceof ApplePayButton );
|
assert( $button instanceof ApplePayButton );
|
||||||
$smart_button = $c->get( 'button.smart-button' );
|
$smart_button = $c->get( 'button.smart-button' );
|
||||||
assert( $smart_button instanceof SmartButtonInterface );
|
assert( $smart_button instanceof SmartButtonInterface );
|
||||||
$page_has_block = has_block( 'woocommerce/checkout' ) || has_block( 'woocommerce/cart' );
|
if ( $smart_button->should_load_ppcp_script() ) {
|
||||||
if ( $smart_button->should_load_ppcp_script() || $page_has_block ) {
|
|
||||||
$button->enqueue();
|
$button->enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( has_block( 'woocommerce/checkout' ) || has_block( 'woocommerce/cart' ) ) {
|
||||||
|
/**
|
||||||
|
* Should add this to the ButtonInterface.
|
||||||
|
*
|
||||||
|
* @psalm-suppress UndefinedInterfaceMethod
|
||||||
|
*/
|
||||||
|
$button->enqueue_styles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
add_action(
|
add_action(
|
||||||
|
|
|
@ -1017,13 +1017,7 @@ class ApplePayButton implements ButtonInterface {
|
||||||
);
|
);
|
||||||
wp_enqueue_script( 'wc-ppcp-applepay' );
|
wp_enqueue_script( 'wc-ppcp-applepay' );
|
||||||
|
|
||||||
wp_register_style(
|
$this->enqueue_styles();
|
||||||
'wc-ppcp-applepay',
|
|
||||||
untrailingslashit( $this->module_url ) . '/assets/css/styles.css',
|
|
||||||
array(),
|
|
||||||
$this->version
|
|
||||||
);
|
|
||||||
wp_enqueue_style( 'wc-ppcp-applepay' );
|
|
||||||
|
|
||||||
wp_localize_script(
|
wp_localize_script(
|
||||||
'wc-ppcp-applepay',
|
'wc-ppcp-applepay',
|
||||||
|
@ -1038,6 +1032,23 @@ class ApplePayButton implements ButtonInterface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueues styles.
|
||||||
|
*/
|
||||||
|
public function enqueue_styles(): void {
|
||||||
|
if ( ! $this->is_enabled() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_register_style(
|
||||||
|
'wc-ppcp-applepay',
|
||||||
|
untrailingslashit( $this->module_url ) . '/assets/css/styles.css',
|
||||||
|
array(),
|
||||||
|
$this->version
|
||||||
|
);
|
||||||
|
wp_enqueue_style( 'wc-ppcp-applepay' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the script data.
|
* Returns the script data.
|
||||||
*
|
*
|
||||||
|
|
|
@ -189,7 +189,6 @@ class GooglepayButton {
|
||||||
callback(el);
|
callback(el);
|
||||||
} else if (timeElapsed > timeout) {
|
} else if (timeElapsed > timeout) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
console.error('Waiting for wrapper timed out.', selector);
|
|
||||||
}
|
}
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,6 +363,23 @@ class Button implements ButtonInterface {
|
||||||
);
|
);
|
||||||
wp_enqueue_script( 'wc-ppcp-googlepay' );
|
wp_enqueue_script( 'wc-ppcp-googlepay' );
|
||||||
|
|
||||||
|
$this->enqueue_styles();
|
||||||
|
|
||||||
|
wp_localize_script(
|
||||||
|
'wc-ppcp-googlepay',
|
||||||
|
'wc_ppcp_googlepay',
|
||||||
|
$this->script_data()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueues styles.
|
||||||
|
*/
|
||||||
|
public function enqueue_styles(): void {
|
||||||
|
if ( ! $this->is_enabled() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wp_register_style(
|
wp_register_style(
|
||||||
'wc-ppcp-googlepay',
|
'wc-ppcp-googlepay',
|
||||||
untrailingslashit( $this->module_url ) . '/assets/css/styles.css',
|
untrailingslashit( $this->module_url ) . '/assets/css/styles.css',
|
||||||
|
@ -370,12 +387,6 @@ class Button implements ButtonInterface {
|
||||||
$this->version
|
$this->version
|
||||||
);
|
);
|
||||||
wp_enqueue_style( 'wc-ppcp-googlepay' );
|
wp_enqueue_style( 'wc-ppcp-googlepay' );
|
||||||
|
|
||||||
wp_localize_script(
|
|
||||||
'wc-ppcp-googlepay',
|
|
||||||
'wc_ppcp_googlepay',
|
|
||||||
$this->script_data()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -89,11 +89,18 @@ class GooglepayModule implements ModuleInterface {
|
||||||
static function () use ( $c, $button ) {
|
static function () use ( $c, $button ) {
|
||||||
$smart_button = $c->get( 'button.smart-button' );
|
$smart_button = $c->get( 'button.smart-button' );
|
||||||
assert( $smart_button instanceof SmartButtonInterface );
|
assert( $smart_button instanceof SmartButtonInterface );
|
||||||
$page_has_block = has_block( 'woocommerce/checkout' ) || has_block( 'woocommerce/cart' );
|
if ( $smart_button->should_load_ppcp_script() ) {
|
||||||
if ( ! $smart_button->should_load_ppcp_script() && ! $page_has_block ) {
|
$button->enqueue();
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
if ( has_block( 'woocommerce/checkout' ) || has_block( 'woocommerce/cart' ) ) {
|
||||||
|
/**
|
||||||
|
* Should add this to the ButtonInterface.
|
||||||
|
*
|
||||||
|
* @psalm-suppress UndefinedInterfaceMethod
|
||||||
|
*/
|
||||||
|
$button->enqueue_styles();
|
||||||
}
|
}
|
||||||
$button->enqueue();
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue