Show notice if cannot init blocks

This commit is contained in:
Alex P 2023-04-19 11:10:35 +03:00
parent f435796cbe
commit 29e1b0cbd0
No known key found for this signature in database
GPG key ID: 54487A734A204D71

View file

@ -34,29 +34,49 @@ class BlocksModule implements ModuleInterface {
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): void {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
if (
! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' )
|| ! function_exists( 'woocommerce_store_api_register_payment_requirements' )
) {
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
$payment_method_registry->register( $c->get( 'blocks.method' ) );
'admin_notices',
function () {
printf(
'<div class="notice notice-error"><p>%1$s</p></div>',
wp_kses_post(
__(
'PayPal checkout block initialization failed, possibly old WooCommerce version or disabled WooCommerce Blocks plugin.',
'woocommerce-paypal-payments'
)
)
);
}
);
woocommerce_store_api_register_payment_requirements(
array(
'data_callback' => function() use ( $c ): array {
$smart_button = $c->get( 'button.smart-button' );
assert( $smart_button instanceof SmartButton );
if ( isset( $smart_button->script_data()['continuation'] ) ) {
return array( 'ppcp_continuation' );
}
return array();
},
)
);
return;
}
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
$payment_method_registry->register( $c->get( 'blocks.method' ) );
}
);
woocommerce_store_api_register_payment_requirements(
array(
'data_callback' => function() use ( $c ): array {
$smart_button = $c->get( 'button.smart-button' );
assert( $smart_button instanceof SmartButton );
if ( isset( $smart_button->script_data()['continuation'] ) ) {
return array( 'ppcp_continuation' );
}
return array();
},
)
);
}
/**