public function __construct($bundled_item_id, $parent)
 {
     $this->item_id = $bundled_item_id;
     $this->product_id = $parent->bundle_data[$bundled_item_id]['product_id'];
     $this->bundle_id = $parent->id;
     $this->item_data = $parent->bundle_data[$bundled_item_id];
     $this->visibility = array('product' => 'visible', 'cart' => 'visible', 'order' => 'visible');
     // Do not process bundled item stock data in the back end, in order to speed things up just a bit.
     $this->is_front_end = WC_PB_Helpers::is_front_end();
     do_action('woocommerce_before_init_bundled_item', $this);
     $bundled_product = wc_get_product($this->product_id);
     // if not present, item cannot be purchased.
     if ($bundled_product) {
         $this->product = $bundled_product;
         $this->title = !empty($this->item_data['override_title']) && $this->item_data['override_title'] === 'yes' ? $this->item_data['product_title'] : $bundled_product->get_title();
         $this->description = !empty($this->item_data['override_description']) && $this->item_data['override_description'] === 'yes' ? $this->item_data['product_description'] : $bundled_product->post->post_excerpt;
         $this->optional = !empty($this->item_data['optional']) && $this->item_data['optional'] === 'yes' ? 'yes' : 'no';
         $this->hide_thumbnail = !empty($this->item_data['hide_thumbnail']) && $this->item_data['hide_thumbnail'] === 'yes' ? 'yes' : 'no';
         $this->quantity = isset($this->item_data['bundle_quantity']) ? absint($this->item_data['bundle_quantity']) : 1;
         $this->discount = !empty($this->item_data['bundle_discount']) ? (double) $this->item_data['bundle_discount'] : 0.0;
         $this->sign_up_discount = !empty($this->item_data['bundle_sign_up_discount']) ? (double) $this->item_data['bundle_sign_up_discount'] : 0.0;
         $this->selection_overrides = !empty($this->item_data['override_defaults']) && $this->item_data['override_defaults'] === 'yes' ? $this->item_data['bundle_defaults'] : '';
         $this->allowed_variations = !empty($this->item_data['filter_variations']) && $this->item_data['filter_variations'] === 'yes' ? $this->item_data['allowed_variations'] : '';
         $this->per_product_pricing = $parent->is_priced_per_product();
         $this->sold_individually = false;
         $this->on_sale = false;
         $this->nyp = false;
         $this->purchasable = false;
         if (!empty($this->item_data['visibility'])) {
             if (is_array($this->item_data['visibility'])) {
                 $this->visibility['product'] = !empty($this->item_data['visibility']['product']) && $this->item_data['visibility']['product'] === 'hidden' ? 'hidden' : 'visible';
                 $this->visibility['cart'] = !empty($this->item_data['visibility']['cart']) && $this->item_data['visibility']['cart'] === 'hidden' ? 'hidden' : 'visible';
                 $this->visibility['order'] = !empty($this->item_data['visibility']['order']) && $this->item_data['visibility']['order'] === 'hidden' ? 'hidden' : 'visible';
             } else {
                 if ($this->item_data['visibility'] === 'hidden') {
                     $this->visibility['product'] = 'hidden';
                 } elseif ($this->item_data['visibility'] === 'secret') {
                     $this->visibility['product'] = $this->visibility['cart'] = $this->visibility['order'] = 'hidden';
                 }
             }
         }
         if ($bundled_product->is_purchasable()) {
             $this->purchasable = true;
             $this->init();
         }
     }
     do_action('woocommerce_after_init_bundled_item', $this);
 }
 /**
  * Update price meta for access in queries. Prices are unfiltered to remain static.
  *
  * @return void
  */
 private function update_price_meta()
 {
     if (apply_filters('woocommerce_bundles_update_price_meta', true, $this)) {
         if (WC_PB_Helpers::is_front_end() && $this->is_priced_per_product()) {
             if ($this->price != $this->min_bundle_price) {
                 update_post_meta($this->id, '_price', $this->min_bundle_price);
             }
             if ($this->is_on_sale()) {
                 if ($this->sale_price != $this->min_bundle_price) {
                     update_post_meta($this->id, '_sale_price', $this->min_bundle_price);
                     delete_transient('wc_products_onsale');
                 }
             } else {
                 if ($this->sale_price !== '') {
                     update_post_meta($this->id, '_sale_price', '');
                     delete_transient('wc_products_onsale');
                 }
             }
             if ($this->regular_price != $this->min_bundle_regular_price) {
                 update_post_meta($this->id, '_regular_price', $this->min_bundle_regular_price);
             }
         }
     }
 }