From d0efa196b4fc32fbe0349cfc5523853cb12abdc1 Mon Sep 17 00:00:00 2001 From: BurakParsAydin Date: Thu, 27 Feb 2025 21:27:26 +0300 Subject: [PATCH 1/3] feat: Add filter to conditionally disable WooPay --- includes/class-wc-payment-gateway-wcpay.php | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index 357c6323d51..fcd5cd84ee2 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -563,6 +563,7 @@ public function get_form_fields() { */ public function init_hooks() { add_action( 'init', [ $this, 'maybe_update_properties_with_country' ] ); + add_action( 'init', [ $this, 'disable_woopay' ] ); // Only add certain actions/filter if this is the main gateway (i.e. not split UPE). if ( self::GATEWAY_ID === $this->id ) { add_action( 'woocommerce_order_actions', [ $this, 'add_order_actions' ] ); @@ -4434,6 +4435,28 @@ private function upe_needs_redirection( $payment_methods ) { return 1 === count( $payment_methods ) && 'card' !== $payment_methods[0]; } + + /** + * Disable WooPay. + * + * This function disables WooPay by updating the option to 'no' + * once the 'disable_woopay' filter is called. + * + * @return boolean False, indicating WooPay is disabled. + */ + public function disable_woopay() { + // Filter: disable_woopay. + $disable = apply_filters( 'disable_woopay', true ); + + // disable WooPay by updating the option to 'no'. + if ( $disable ) { + $this->update_option( 'platform_checkout', 'no' ); + } + + return false; + } + + /** * Handles the shipping requirement for Afterpay payments. * From f6ebc16504d0371b8a90825605a8664ad0aebe03 Mon Sep 17 00:00:00 2001 From: BurakParsAydin Date: Thu, 27 Feb 2025 21:29:53 +0300 Subject: [PATCH 2/3] Add the changelog --- changelog/update-9938 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/update-9938 diff --git a/changelog/update-9938 b/changelog/update-9938 new file mode 100644 index 00000000000..8a16958c514 --- /dev/null +++ b/changelog/update-9938 @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +New Filter: disable_woopay – Allows developers to conditionally disable WooPay based on custom logic, improving compatibility with themes and plugins. From 1992336f1e24e6bb8bb2cfb24b14c543550bba74 Mon Sep 17 00:00:00 2001 From: BurakParsAydin Date: Fri, 28 Feb 2025 19:11:28 +0300 Subject: [PATCH 3/3] Change the default value to false --- includes/class-wc-payment-gateway-wcpay.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index fcd5cd84ee2..73cc5293553 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -4446,7 +4446,7 @@ private function upe_needs_redirection( $payment_methods ) { */ public function disable_woopay() { // Filter: disable_woopay. - $disable = apply_filters( 'disable_woopay', true ); + $disable = apply_filters( 'disable_woopay', false ); // disable WooPay by updating the option to 'no'. if ( $disable ) {