mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add filter woocommerce_paypal_payments_<context>_button_disabled to disable PayPal buttons on a given context.
This commit is contained in:
parent
cdd4a69bf5
commit
74f28ca921
4 changed files with 73 additions and 11 deletions
|
@ -1357,20 +1357,43 @@ class SmartButton implements SmartButtonInterface {
|
|||
* @return bool
|
||||
*/
|
||||
protected function is_button_disabled(): bool {
|
||||
if ( 'product' !== $this->context() ) {
|
||||
return false;
|
||||
$context = $this->context();
|
||||
|
||||
if ( 'product' === $context ) {
|
||||
$product = wc_get_product();
|
||||
|
||||
/**
|
||||
* Allows to decide if the button should be disabled for a given product
|
||||
*/
|
||||
if ( ( $isDisabled = apply_filters(
|
||||
'woocommerce_paypal_payments_product_button_disabled',
|
||||
null,
|
||||
$product )
|
||||
) !== null) {
|
||||
return $isDisabled;
|
||||
}
|
||||
} else {
|
||||
$filterName = 'woocommerce_paypal_payments_'
|
||||
. str_replace('-', '_', $context)
|
||||
. '_button_disabled';
|
||||
|
||||
/**
|
||||
* Allows to decide if the button should be disabled in a given context
|
||||
*/
|
||||
if ( ( $isDisabled = apply_filters( $filterName, null ) ) !== null ) {
|
||||
return $isDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
$product = wc_get_product();
|
||||
if ( ( $isDisabled = apply_filters(
|
||||
'woocommerce_paypal_payments_button_disabled',
|
||||
null,
|
||||
$context
|
||||
) ) !== null ) {
|
||||
return $isDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to decide if the button should be disabled for a given product
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_product_button_disabled',
|
||||
false,
|
||||
$product
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue