From dc4b54b9b96df754c57500b2aa39c60a47caefeb Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 20 Feb 2025 13:09:14 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20Add=20and=20update=20hook=20comm?=
=?UTF-8?q?ents?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../LocalAlternativePaymentMethodsModule.php | 26 ++++++++++++++-----
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
index 1d24b80f5..9f5723240 100644
--- a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
+++ b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
@@ -48,6 +48,11 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
return true;
}
+ /**
+ * The "woocommerce_payment_gateways" filter is responsible for ADDING
+ * custom payment gateways to WooCommerce. Here, we add all the local
+ * APM gateways to the filtered list, so they become available later on.
+ */
add_filter(
'woocommerce_payment_gateways',
/**
@@ -56,12 +61,12 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType
*/
function ( $methods ) use ( $c ) {
- $is_connected = $c->get( 'settings.flag.is-connected' );
- if ( ! $is_connected ) {
+ if ( ! is_array( $methods ) ) {
return $methods;
}
- if ( ! is_array( $methods ) ) {
+ $is_connected = $c->get( 'settings.flag.is-connected' );
+ if ( ! $is_connected ) {
return $methods;
}
@@ -74,13 +79,14 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
}
);
+ /**
+ * Filters the "available gateways" list by REMOVING gateways that
+ * are not available for the current customer.
+ */
add_filter(
'woocommerce_available_payment_gateways',
/**
- * Filters the "available gateways" list by removing gateways that
- * are not available for the current customer.
- *
- * This callback only _removes_ items from the payment gateway list.
+ * Param types removed to avoid third-party issues.
*
* @psalm-suppress MissingClosureParamType
*/
@@ -108,6 +114,12 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
}
);
+ /**
+ * Adds all local APM gateways in the "payment_method_type" block registry
+ * to make the payment methods available in the Block Checkout.
+ *
+ * @see IntegrationRegistry::initialize
+ */
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {