️ Optimize PayPal SDK loading for block contexts

This commit is contained in:
Philipp Stracker 2024-11-27 17:35:07 +01:00
parent d6a130bb24
commit 47b57058fb
No known key found for this signature in database
2 changed files with 15 additions and 5 deletions

View file

@ -143,10 +143,15 @@ class BlocksModule implements ServiceModule, ExtendingModule, ExecutableModule {
add_filter(
'woocommerce_paypal_payments_sdk_components_hook',
function( array $components ) {
$components[] = 'buttons';
function( array $components, string $context ) {
if ( str_ends_with( $context, '-block' ) ) {
$components[] = 'buttons';
}
return $components;
}
},
10,
2
);
return true;
}

View file

@ -1594,10 +1594,15 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
*
* @internal Matches filter name in APM extension.
*
* @param array $components The array of components already registered.
* @param array $components The array of components already registered.
* @param string $context The SmartButton context.
*/
return array_unique(
(array) apply_filters( 'woocommerce_paypal_payments_sdk_components_hook', $components )
(array) apply_filters(
'woocommerce_paypal_payments_sdk_components_hook',
$components,
$this->context()
)
);
}