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. diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index 357c6323d51..73cc5293553 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', false ); + + // 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. *