is_type( 'composite' ) ) { return $price; } // Parent Component Price $base_price = $price; $feed_rules = $config->get_config(); if ( isset( $feed_rules['composite_price'] ) && 'all_product_price' === $feed_rules['composite_price'] ) { $components_price = 0; $components = $product->get_components(); if ( ! empty( $components ) && is_array( $components ) ) { foreach ( $components as $component ) { if ( ! isset( $component['products'] ) || empty( $component['products'] ) ) { continue; } $products = $component['products']; foreach ( $products as $product_id ) { $default_product = wc_get_product( $product_id ); if ( ! is_object( $default_product ) || ! $default_product->is_in_stock() ) { continue; } $quantity = 1; if ( isset( $component['qty'] ) && $component['qty'] > 0 ) { $quantity = $component['qty']; } if ( 'products' === $component['type'] && empty( $component['price'] ) ) { $components_price += $price; $components_price *= $quantity; } elseif ( 'products' === $component['type'] && ! empty( $component['price'] ) ) { $clever = new \WPCleverWooco; $old_price = $price; $new_price = $component['price']; $components_price += $clever::get_new_price( $old_price, $new_price ); $components_price *= $quantity; } break; // Get first in stock product from component options. } } // Apply discount to components price. $discount = $product->get_discount(); if ( $discount > 0 ) { $components_price -= $discount / 100 * $components_price; } } if ( 'exclude' === $product->get_pricing() ) { $price = $components_price; } elseif ( 'include' === $product->get_pricing() ) { $price = $components_price + $base_price; } elseif ( 'only' === $product->get_pricing() ) { $price = $base_price; } } else { $price = $base_price; } if ( $price > 0 ) { return $price; } return ''; } }