-
Notifications
You must be signed in to change notification settings - Fork 72
Add Filter to Disable WooPay for Improved Compatibility #10468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
Comment on lines
+4447
to
+4457
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation creates a permanent change in the DB, which is not a good practice. Filters and actions should typically control behavior at runtime without causing permanent side effects. For example, what would happen if a plugin hooking into add_action( 'plugins_loaded', function () {
// maybe a plugin would like to disable the WooPay button on product pages. But with the current implementation, it would disable WooPay on subsequent requests of checkout pages as well.
if ( is_product() ) {
add_filter( 'disable_woopay', '__return_true' );
}
} ); |
||
|
||
|
||
/** | ||
* Handles the shipping requirement for Afterpay payments. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false
will always returned, whether WooPay has been disabled or not.Is
return false
needed? Can the function just returnvoid
?