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:
Alex P 2024-01-09 23:14:18 +02:00
parent 02722a3c97
commit 03a6817e18
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 7 additions and 13 deletions

View file

@ -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;
}
}

View file

@ -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;
}