mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Show notice if cannot init blocks
This commit is contained in:
parent
f435796cbe
commit
29e1b0cbd0
1 changed files with 38 additions and 18 deletions
|
@ -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();
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue