mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Add woocommerce_paypal_payments_buttons_paylater_disabled and woocommerce_paypal_payments_product_buttons_paylater_disabled filters
This commit is contained in:
parent
81f6340897
commit
d71e09bd09
2 changed files with 84 additions and 6 deletions
|
@ -382,7 +382,11 @@ class SmartButton implements SmartButtonInterface {
|
||||||
* @throws NotFoundException When a setting was not found.
|
* @throws NotFoundException When a setting was not found.
|
||||||
*/
|
*/
|
||||||
private function render_message_wrapper_registrar(): bool {
|
private function render_message_wrapper_registrar(): bool {
|
||||||
if ( ! $this->settings_status->is_pay_later_messaging_enabled() ) {
|
if ( ! $this->is_pay_later_messaging_enabled() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $this->is_pay_later_filter_enabled_for_location( $this->context() ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,7 +552,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
|
|
||||||
$smart_button_enabled_for_current_location = $this->settings_status->is_smart_button_enabled_for_location( $this->context() );
|
$smart_button_enabled_for_current_location = $this->settings_status->is_smart_button_enabled_for_location( $this->context() );
|
||||||
$smart_button_enabled_for_mini_cart = $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' );
|
$smart_button_enabled_for_mini_cart = $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' );
|
||||||
$messaging_enabled_for_current_location = $this->settings_status->is_pay_later_messaging_enabled_for_location( $this->context() );
|
$messaging_enabled_for_current_location = $this->is_pay_later_messaging_enabled_for_location( $this->context() );
|
||||||
|
|
||||||
switch ( $this->context() ) {
|
switch ( $this->context() ) {
|
||||||
case 'checkout':
|
case 'checkout':
|
||||||
|
@ -657,7 +661,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
* @throws NotFoundException When a setting was not found.
|
* @throws NotFoundException When a setting was not found.
|
||||||
*/
|
*/
|
||||||
private function message_values(): array {
|
private function message_values(): array {
|
||||||
if ( ! $this->settings_status->is_pay_later_messaging_enabled() ) {
|
if ( ! $this->is_pay_later_messaging_enabled() ) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1073,8 +1077,8 @@ class SmartButton implements SmartButtonInterface {
|
||||||
|
|
||||||
$enable_funding = array( 'venmo' );
|
$enable_funding = array( 'venmo' );
|
||||||
|
|
||||||
if ( $this->settings_status->is_pay_later_button_enabled_for_location( $context ) ||
|
if ( $this->is_pay_later_button_enabled_for_location( $context ) ||
|
||||||
$this->settings_status->is_pay_later_messaging_enabled_for_location( $context )
|
$this->is_pay_later_messaging_enabled_for_location( $context )
|
||||||
) {
|
) {
|
||||||
$enable_funding[] = 'paylater';
|
$enable_funding[] = 'paylater';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1408,6 +1412,80 @@ class SmartButton implements SmartButtonInterface {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks a filter if pay_later/messages should be rendered on a given location / context.
|
||||||
|
*
|
||||||
|
* @param string $location The location.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function is_pay_later_filter_enabled_for_location( string $location ): bool {
|
||||||
|
|
||||||
|
if ( 'product' === $location ) {
|
||||||
|
$product = wc_get_product();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to decide if the button should be disabled for a given product
|
||||||
|
*/
|
||||||
|
$is_disabled = apply_filters(
|
||||||
|
'woocommerce_paypal_payments_product_buttons_paylater_disabled',
|
||||||
|
null,
|
||||||
|
$product
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $is_disabled !== null ) {
|
||||||
|
return ! $is_disabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to decide if the button should be disabled globally or on a given context
|
||||||
|
*/
|
||||||
|
$is_disabled = apply_filters(
|
||||||
|
'woocommerce_paypal_payments_buttons_paylater_disabled',
|
||||||
|
null,
|
||||||
|
$location
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $is_disabled !== null ) {
|
||||||
|
return ! $is_disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether Pay Later button is enabled for a given location.
|
||||||
|
*
|
||||||
|
* @param string $location The location.
|
||||||
|
* @return bool true if is enabled, otherwise false.
|
||||||
|
*/
|
||||||
|
private function is_pay_later_button_enabled_for_location( string $location ) {
|
||||||
|
return $this->is_pay_later_filter_enabled_for_location( $location )
|
||||||
|
&& $this->settings_status->is_pay_later_button_enabled_for_location( $location );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether Pay Later message is enabled for a given location.
|
||||||
|
*
|
||||||
|
* @param string $location The location setting name.
|
||||||
|
* @return bool true if is enabled, otherwise false.
|
||||||
|
*/
|
||||||
|
private function is_pay_later_messaging_enabled_for_location( string $location ) {
|
||||||
|
return $this->is_pay_later_filter_enabled_for_location( $location )
|
||||||
|
&& $this->settings_status->is_pay_later_messaging_enabled_for_location( $location );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether Pay Later message is enabled
|
||||||
|
*
|
||||||
|
* @return bool true if is enabled, otherwise false.
|
||||||
|
*/
|
||||||
|
private function is_pay_later_messaging_enabled() {
|
||||||
|
return $this->is_pay_later_filter_enabled_for_location( $this->context() )
|
||||||
|
&& $this->settings_status->is_pay_later_messaging_enabled();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all payment tokens for the user, via API or cached if already queried.
|
* Retrieves all payment tokens for the user, via API or cached if already queried.
|
||||||
*
|
*
|
||||||
|
|
|
@ -167,7 +167,7 @@ class SettingsListener {
|
||||||
/**
|
/**
|
||||||
* Listens if the merchant ID should be updated.
|
* Listens if the merchant ID should be updated.
|
||||||
*/
|
*/
|
||||||
public function listen_for_merchant_id() {
|
public function listen_for_merchant_id(): void {
|
||||||
if ( ! $this->is_valid_site_request() || $this->state->current_state() === State::STATE_ONBOARDED ) {
|
if ( ! $this->is_valid_site_request() || $this->state->current_state() === State::STATE_ONBOARDED ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue