From 03a6817e183f2a21bbb07f88fe81006627f14181 Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 9 Jan 2024 23:14:18 +0200 Subject: [PATCH] Use only variation from cart for PUI check This function is also used for order-pay page, but it already retrieves the variation. --- .../ppcp-wc-gateway/src/Helper/CheckoutHelper.php | 14 ++------------ .../src/Helper/PayUponInvoiceHelper.php | 6 +++++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php b/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php index bd21df4c2..1347e6797 100644 --- a/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/CheckoutHelper.php @@ -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; } } diff --git a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php index 8ba589789..823caf611 100644 --- a/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php +++ b/modules/ppcp-wc-gateway/src/Helper/PayUponInvoiceHelper.php @@ -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; }