mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Use only variation from cart for PUI check
This function is also used for order-pay page, but it already retrieves the variation.
This commit is contained in:
parent
02722a3c97
commit
03a6817e18
2 changed files with 7 additions and 13 deletions
|
@ -91,24 +91,14 @@ class CheckoutHelper {
|
|||
/**
|
||||
* Ensures product is neither downloadable nor virtual.
|
||||
*
|
||||
* @param WC_Product $product WC product.
|
||||
* @param WC_Product $product WC product (can be a variation).
|
||||
* @return bool
|
||||
*/
|
||||
public function is_physical_product( WC_Product $product ):bool {
|
||||
public function is_physical_product( WC_Product $product ): bool {
|
||||
if ( $product->is_downloadable() || $product->is_virtual() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( is_a( $product, WC_Product_Variable::class ) ) {
|
||||
foreach ( $product->get_available_variations( 'object' ) as $variation ) {
|
||||
if ( is_a( $variation, WC_Product_Variation::class ) ) {
|
||||
if ( true === $variation->is_downloadable() || true === $variation->is_virtual() ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,11 @@ class PayUponInvoiceHelper {
|
|||
if ( $cart && ! is_checkout_pay_page() ) {
|
||||
$items = $cart->get_cart_contents();
|
||||
foreach ( $items as $item ) {
|
||||
$product = wc_get_product( $item['product_id'] );
|
||||
$product_id = $item['product_id'];
|
||||
if ( isset( $item['variation_id'] ) && $item['variation_id'] ) {
|
||||
$product_id = $item['variation_id'];
|
||||
}
|
||||
$product = wc_get_product( $product_id );
|
||||
if ( $product && ! $this->checkout_helper->is_physical_product( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue