Skip to content

Commit e6aa495

Browse files
Delay the get_gateways() call until after we're inside the hook callback
1 parent 478d3ca commit e6aa495

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

woocommerce/payment-gateway/Blocks/Gateway_Blocks_Handler.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,28 @@ public function __construct( SV_WC_Payment_Gateway_Plugin $plugin ) {
4545
*
4646
* @return void
4747
*/
48-
public function handle_blocks_integration() : void {
49-
50-
if ( ! class_exists( PaymentMethodRegistry::class ) || ! class_exists( WooCommerceBlocks::class ) || ! version_compare( WooCommerceBlocks::get_version(), '4.4.0', '>' ) ) {
48+
public function handle_blocks_integration() : void
49+
{
50+
if (
51+
! class_exists(PaymentMethodRegistry::class) ||
52+
! class_exists(WooCommerceBlocks::class) ||
53+
! version_compare(WooCommerceBlocks::get_version(), '4.4.0', '>')
54+
) {
5155
return;
5256
}
5357

54-
if ( $this->is_checkout_block_compatible() ) {
55-
56-
/** @var SV_WC_Payment_Gateway_Plugin $plugin */
57-
$plugin = $this->plugin;
58-
59-
foreach ( $plugin->get_gateways() as $gateway ) {
60-
61-
if ( $checkout_integration = $gateway->get_checkout_block_integration_instance() ) {
58+
if ($this->is_checkout_block_compatible()) {
59+
add_action('woocommerce_blocks_payment_method_type_registration', function (PaymentMethodRegistry $payment_method_registry) {
60+
if (! $this->plugin instanceof SV_WC_Payment_Gateway_Plugin) {
61+
return;
62+
}
6263

63-
add_action('woocommerce_blocks_payment_method_type_registration', function ( PaymentMethodRegistry $payment_method_registry ) use ( $checkout_integration ) {
64-
$payment_method_registry->register( $checkout_integration );
65-
}
66-
);
64+
foreach ($this->plugin->get_gateways() as $gateway) {
65+
if ($checkout_integration = $gateway->get_checkout_block_integration_instance()) {
66+
$payment_method_registry->register($checkout_integration);
67+
}
6768
}
68-
}
69+
});
6970
}
7071
}
7172

0 commit comments

Comments
 (0)