/** * Returns this product's available variations array. * * @return array */ public function get_product_variations() { if (!empty($this->product_variations)) { return $this->product_variations; } if ($this->product->product_type === 'variable' || $this->product->product_type === 'variable-subscription') { do_action('woocommerce_before_init_bundled_item', $this); // Filter children to exclude filtered out variations. add_filter('woocommerce_get_children', array($this, 'bundled_item_children'), 10, 2); // Filter variations data. add_filter('woocommerce_available_variation', array($this, 'bundled_item_available_variation'), 10, 3); $this->add_price_filters(); if ($this->product->product_type === 'variable-subscription') { WC_PB_Helpers::$bundled_item = $this; } $bundled_item_variations = $this->product->get_available_variations(); if ($this->product->product_type === 'variable-subscription') { WC_PB_Helpers::$bundled_item = false; } $this->remove_price_filters(); remove_filter('woocommerce_available_variation', array($this, 'bundled_item_available_variation'), 10, 3); remove_filter('woocommerce_get_children', array($this, 'bundled_item_children'), 10, 2); do_action('woocommerce_after_init_bundled_item', $this); // Add only active variations. foreach ($bundled_item_variations as $variation_data) { if (!empty($variation_data)) { $this->product_variations[] = $variation_data; } } return $this->product_variations; } return false; }
/** * Remove price filters after modifying child product prices depending on the per-product pricing option state, including any discounts defined at bundled item level. * * @return void */ public static function remove_price_filters() { self::$bundled_item = false; remove_filter('woocommerce_get_price', array(__CLASS__, 'filter_get_price'), 15, 2); remove_filter('woocommerce_get_sale_price', array(__CLASS__, 'filter_get_sale_price'), 15, 2); remove_filter('woocommerce_get_regular_price', array(__CLASS__, 'filter_get_regular_price'), 15, 2); remove_filter('woocommerce_get_price_html', array(__CLASS__, 'filter_get_price_html'), 10, 2); remove_filter('woocommerce_show_variation_price', array(__CLASS__, 'filter_show_variation_price'), 10, 3); remove_filter('woocommerce_get_variation_price_html', array(__CLASS__, 'filter_get_price_html'), 10, 2); remove_filter('woocommerce_variation_prices', array(__CLASS__, 'filter_get_variation_prices'), 10, 3); }