is_type( 'bundle' ) ) { return $price; } $bundle = new \WC_Product_Bundled( $product->get_id() ); $price_display = ''; if ( ! is_null( $bundle->options['price_display'] ) ) { $price_display = $bundle->options['price_display']; } $product_ids = $bundle->options['product_ids']; // Set discount $discount = 0; if ( ! empty( $bundle->options['fixed_discount'] ) ) { $discount = $bundle->options['fixed_discount']; } // Get price if ( is_array( $product_ids ) ) { $prices = array(); foreach ( $product_ids as $pid ) { $product = wc_get_product( $pid ); switch ( $price_type ) { case 'regular_price': $prices[] = $product->get_regular_price(); break; case 'sale_price': $prices[] = $product->get_sale_price(); break; default: $prices[] = $product->get_price(); break; } } if ( 'range' === $price_display ) { $price = min( $prices ); } else { $price = array_sum( $prices ); } } // Get sale price if discount enabled if ( $discount && 'regular_price' !== $price_type ) { $price -= $discount; } // Get WooCommerce Multi language Price by Currency. $price = $this->convert_currency( $price, $price_type, $product, $config ); // Get Price with tax $price = $this->add_tax( $price, $product, $with_tax ); if ( $price > 0 ) { return $price; } return ''; } /** * Get Regular Price. * * @param int $price product price. * @param \WC_Product $product product object. * @param \CTXFeed\V5\Utility\Config $config config object. * @param bool $with_tax price with tax or without tax. * @param string $price_type price type regular_price, price, sale_price. * @return float|int|string */ public function regular_price( $price, $product, $config, $with_tax, $price_type ) { return $this->bundle_price( $price, $product, $config, $with_tax, 'regular_price', $price_type ); } /** * Get Price. * * @param int $price product price. * @param \WC_Product $product product object. * @param \CTXFeed\V5\Utility\Config $config config object. * @param bool $with_tax price with tax or without tax. * @param string $price_type price type regular_price, price, sale_price. * @return float|int|string */ public function price( $price, $product, $config, $with_tax, $price_type ) { return $this->bundle_price( $price, $product, $config, $with_tax, $price_type ); } /** * Get Sale Price. * * @param int $price product price. * @param \WC_Product_Bundled $product product object. * @param \CTXFeed\V5\Utility\Config $config config object. * @param bool $with_tax price with tax or without tax. * @param string $price_type price type regular_price, price, sale_price. * @return float|int */ public function sale_price( $price, $product, $config, $with_tax, $price_type ) { return $this->bundle_price( $price, $product, $config, $with_tax, $price_type ); } /** * Convert currency if WooCommerce Multi language plugin is active. * * @param int $price product price. * @param string $price_type price type regular_price, price, sale_price. * @param \WC_Product_Bundled $product product object. * @param \CTXFeed\V5\Utility\Config $config config object. * @return float|int|string */ public function convert_currency( $price, $price_type, $product, $config ) { return apply_filters( 'woo_feed_wcml_price', $price, $product->get_id(), $config->get_feed_currency(), '_' . $price_type ); } /** * Should add tax or not. * * @param int $price product price. * @param \WC_Product_Bundled $product product object. * @param bool $with_tax price with tax or without tax. * @return float|int|string */ public function add_tax( $price, $product, $with_tax = false ) { if ( true === $with_tax ) { return ProductHelper::get_price_with_tax( $price, $product ); } return $price; } }