/** * Price-related filters. Modify composited product prices to take into account component discounts. * * @param WC_Product $product * @param string $component_id * @param WC_Product_Composite $composite * @return void */ public function apply_composited_product_filters($product, $component_id, $composite) { $component_data = $composite->get_component_data($component_id); $quantity_min = $component_data['quantity_min']; $quantity_max = $component_data['quantity_max']; if ($product->sold_individually === 'yes') { $quantity_max = 1; $quantity_min = min($quantity_min, 1); } $this->filter_params['product'] = $product; $this->filter_params['composite'] = $composite; $this->filter_params['composite_id'] = $composite->id; $this->filter_params['component_id'] = $component_id; $this->filter_params['discount'] = isset($component_data['discount']) ? $component_data['discount'] : 0; $this->filter_params['per_product_pricing'] = $composite->is_priced_per_product(); $this->filter_params['quantity_min'] = $quantity_min; $this->filter_params['quantity_max'] = $quantity_max; add_filter('woocommerce_available_variation', array($this, 'filter_available_variation'), 10, 3); add_filter('woocommerce_get_price', array($this, 'filter_show_product_get_price'), 16, 2); add_filter('woocommerce_get_regular_price', array($this, 'filter_show_product_get_regular_price'), 16, 2); add_filter('woocommerce_get_sale_price', array($this, 'filter_show_product_get_sale_price'), 16, 2); add_filter('woocommerce_get_price_html', array($this, 'filter_show_product_get_price_html'), 5, 2); add_filter('woocommerce_get_variation_price_html', array($this, 'filter_show_product_get_price_html'), 5, 2); add_filter('woocommerce_bundles_update_price_meta', array($this, 'filter_show_product_bundles_update_price_meta'), 10, 2); add_filter('woocommerce_bundle_is_composited', array($this, 'filter_bundle_is_composited'), 10, 2); add_filter('woocommerce_bundle_is_priced_per_product', array($this, 'filter_bundle_is_priced_per_product'), 10, 2); add_filter('woocommerce_bundle_get_base_price', array($this, 'filter_show_product_get_base_price'), 16, 2); add_filter('woocommerce_bundle_get_base_regular_price', array($this, 'filter_show_product_get_base_regular_price'), 16, 2); add_filter('woocommerce_nyp_html', array($this, 'filter_show_product_get_nyp_price_html'), 15, 2); do_action('woocommerce_composite_products_apply_product_filters', $product, $component_id, $composite); }
/** * Composited Simple product price. * * @param WC_Product $product * @param string $component_id * @param WC_Product_Composite $composite * @return void */ function wc_cp_composited_product_price($product, $component_id, $composite) { if ($product->product_type === 'simple') { if ($composite->is_priced_per_product() && $product->get_price() !== '') { wc_get_template('composited-product/price.php', array('product' => $product), '', WC_CP()->plugin_path() . '/templates/'); } } }
/** * Outputs nyp markup. * * @param WC_Product $product * @param int $component_id * @param WC_Product_Composite $composite_product * @return void */ public static function nyp_display_support($product, $component_id, $composite_product) { if (false === $composite_product->is_priced_per_product()) { return; } if (function_exists('WC_Name_Your_Price') && ($product->product_type === 'simple' || $product->product_type === 'bundle')) { WC_Name_Your_Price()->display->display_price_input($product->id, '-' . $component_id); } }