mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Extract filter to a function
This commit is contained in:
parent
c7801bc734
commit
fc3ba70d4b
1 changed files with 27 additions and 7 deletions
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Button\Assets;
|
|||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WC_Product;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
|
@ -524,9 +525,8 @@ class SmartButton implements SmartButtonInterface {
|
|||
$product = wc_get_product();
|
||||
|
||||
if (
|
||||
! is_checkout() && is_a( $product, \WC_Product::class )
|
||||
&& ( ! apply_filters( 'woocommerce_paypal_payments_product_supports_payment_request_button', ! $product->is_type( array( 'external', 'grouped' ) ) && $product->is_in_stock(), $product )
|
||||
)
|
||||
! is_checkout() && is_a( $product, WC_Product::class )
|
||||
&& ! $this->product_supports_payment( $product )
|
||||
) {
|
||||
|
||||
return;
|
||||
|
@ -550,9 +550,11 @@ class SmartButton implements SmartButtonInterface {
|
|||
$product = wc_get_product();
|
||||
|
||||
if (
|
||||
! is_checkout() && is_a( $product, \WC_Product::class )
|
||||
&& ( ! apply_filters( 'woocommerce_paypal_payments_product_supports_payment_request_button', ! $product->is_type( array( 'external', 'grouped' ) ) && $product->is_in_stock(), $product )
|
||||
)
|
||||
! is_checkout() && is_a( $product, WC_Product::class )
|
||||
/**
|
||||
* The filter returning true if PayPal buttons can be rendered, or false otherwise.
|
||||
*/
|
||||
&& ! $this->product_supports_payment( $product )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -576,7 +578,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
}
|
||||
$placement = 'product';
|
||||
$product = wc_get_product();
|
||||
$amount = ( is_a( $product, \WC_Product::class ) ) ? wc_get_price_including_tax( $product ) : 0;
|
||||
$amount = ( is_a( $product, WC_Product::class ) ) ? wc_get_price_including_tax( $product ) : 0;
|
||||
$layout = $this->settings->has( 'message_product_layout' ) ?
|
||||
$this->settings->get( 'message_product_layout' ) : 'text';
|
||||
$logo_type = $this->settings->has( 'message_product_logo' ) ?
|
||||
|
@ -1235,6 +1237,24 @@ class SmartButton implements SmartButtonInterface {
|
|||
return WC()->cart->get_cart_contents_total() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if PayPal buttons/messages can be rendered for the given product.
|
||||
*
|
||||
* @param WC_Product $product The product.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function product_supports_payment( WC_Product $product ): bool {
|
||||
/**
|
||||
* The filter returning true if PayPal buttons/messages can be rendered for this product, or false otherwise.
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_product_supports_payment_request_button',
|
||||
! $product->is_type( array( 'external', 'grouped' ) ) && $product->is_in_stock(),
|
||||
$product
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all payment tokens for the user, via API or cached if already queried.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue