/** * 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 single variation template. * * @param WC_Product_Variable $product * @param string $component_id * @param WC_Product_Composite $composite * @return void */ function wc_cp_composited_single_variation($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); } wc_get_template('composited-product/variation.php', array('quantity_min' => $quantity_min, 'quantity_max' => $quantity_max, 'component_id' => $component_id, 'product' => $product, 'composite_product' => $composite), '', WC_CP()->plugin_path() . '/templates/'); }
/** * Show component options. * * @param string $component_id * @param WC_Product_Composite $product * @return void */ public function wc_cp_add_component_options($component_id, $product) { global $woocommerce_composite_products; // Default Component Option $selected_option = $product->get_component_default_option($component_id); // Component Options template wc_get_template('single-product/component-options.php', array('product' => $product, 'component_id' => $component_id, 'component_options' => $product->get_current_component_options($component_id), 'component_data' => $product->get_component_data($component_id), 'selected_option' => $selected_option), '', $woocommerce_composite_products->plugin_path() . '/templates/'); }