/**
  * Get composited products prices via their WC_CP_Product wrapper to account for discounts.
  *
  * @param  int                  $product_id
  * @param  mixed                $variation_id
  * @param  string               $component_id
  * @param  WC_Product_Composite $composite
  * @return double
  */
 private function get_composited_cart_item_price($product_id, $variation_id, $component_id, $composite)
 {
     if (!$product_id) {
         return 0;
     }
     $composited_product_wrapper = $composite->get_composited_product($component_id, $product_id);
     if (!$composited_product_wrapper || !$composited_product_wrapper->exists()) {
         return false;
     }
     $composited_product = $composited_product_wrapper->get_product();
     $composited_product_type = $composited_product->product_type;
     $composited_product_price = 0;
     $composited_product_wrapper->add_filters();
     if ($composited_product_type === 'variable' && $variation_id > 0) {
         $variation = $composited_product->get_child($variation_id);
         if ($variation) {
             $composited_product_price = $variation->get_price();
         }
     } else {
         $composited_product_price = $composited_product->get_price();
     }
     $composited_product_wrapper->remove_filters();
     return $composited_product_price;
 }
/**
 * 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/');
}
 /**
  * Get composited products prices via their WC_CP_Product wrapper to account for discounts.
  *
  * @param  int                  $product_id
  * @param  mixed                $variation_id
  * @param  string               $component_id
  * @param  WC_Product_Composite $composite
  * @return double
  */
 function wc_cp_get_composited_product_price($product_id, $variation_id, $component_id, $composite)
 {
     if (!$product_id) {
         return 0;
     }
     $composited_product_wrapper = $composite->get_composited_product($component_id, $product_id);
     if (!$composited_product_wrapper || !$composited_product_wrapper->exists()) {
         return false;
     }
     $composited_product = $composited_product_wrapper->get_product();
     $composited_product_type = $composited_product->product_type;
     $composited_product_price = 0;
     $composited_product_wrapper->add_filters();
     if ($composited_product_type === 'simple') {
         $composited_product_price = $composited_product->get_price();
     } elseif ($composited_product_type === 'bundle') {
         if (!$composited_product->is_priced_per_product()) {
             $composited_product_price = $composited_product->get_price();
         }
     } elseif ($composited_product_type === 'variable' && $variation_id > 0) {
         $variation = $composited_product->get_child($variation_id);
         if ($variation) {
             $composited_product_price = $variation->get_price();
         }
     }
     $composited_product_wrapper->remove_filters();
     return $composited_product_price;
 }
 /**
  * Enable/disable the toggle-box component view when a Single-page layout is active
  * @param  boolean              $show_toggle
  * @param  string               $component_id
  * @param  WC_Product_Composite $product
  * @return boolean
  */
 function swc_cp_component_toggled($show_toggle, $component_id, $product)
 {
     $show_toggle = get_theme_mod('swc_cp_component_toggled', 'progressive');
     $style = $product->get_composite_layout_style();
     if ($style === $show_toggle || $show_toggle === 'both') {
         return true;
     }
     return false;
 }
 function components_update($product_id, $data)
 {
     $this->sync_composite_data_across_translations($product_id);
     $product = new WC_Product_Composite($product_id);
     $composite_data = $product->get_composite_data();
     if (!empty($data['wc_composite_component'])) {
         foreach ($data['wc_composite_component'] as $component_id => $component) {
             if (!empty($component['title'])) {
                 $composite_data[$component_id]['title'] = $component['title'];
             }
             if (!empty($component['description'])) {
                 $composite_data[$component_id]['description'] = $component['description'];
             }
         }
         update_post_meta($product_id, '_bto_data', $composite_data);
     }
 }
 /**
  * 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);
 }
 /**
  * Add-to-cart section in single-page mode -- added at the end of everything.
  *
  * @param  string               $component_id
  * @param  WC_Product_Composite $product
  * @return void
  */
 public function wc_cp_add_single_mode_cart($components, $product)
 {
     global $woocommerce_composite_products;
     $navigation_style = $product->get_composite_layout_style();
     if ($navigation_style === 'single' || $navigation_style === 'progressive') {
         // Add to cart section
         wc_get_template('single-product/composite-add-to-cart.php', array('product' => $product, 'components' => $components, 'navigation_style' => $navigation_style, 'navigation_style_variation' => $product->get_composite_layout_style_variation(), 'selection_mode' => $product->get_composite_selections_style()), '', $woocommerce_composite_products->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);
     }
 }