"> <option value=""><?php echo __('Choose an option', 'woocommerce'); ?> …</option><?php if (is_array($options)) { if (isset($_REQUEST[$bundle_fields_prefix . 'bundle_attribute_' . sanitize_title($name) . '_' . $bundled_item->item_id])) { $selected_value = $_REQUEST[$bundle_fields_prefix . 'bundle_attribute_' . sanitize_title($name) . '_' . $bundled_item->item_id]; } elseif (isset($bundled_product_selected_attributes[sanitize_title($name)])) { $selected_value = $bundled_product_selected_attributes[sanitize_title($name)]; } else { $selected_value = ''; } // Placeholder: Do not show filtered-out (disabled) options if (taxonomy_exists($name)) { $terms = wc_bundles_get_product_terms($bundled_product->id, $name, array('fields' => 'all')); foreach ($terms as $term) { if (!in_array($term->slug, $options)) { continue; } echo '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($selected_value), sanitize_title($term->slug), false) . '>' . apply_filters('woocommerce_variation_option_name', $term->name) . '</option>'; } } else { foreach ($options as $option) { echo '<option value="' . esc_attr(sanitize_title($option)) . '" ' . selected(sanitize_title($selected_value), sanitize_title($option), false) . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>'; } } } ?> </select><?php if (sizeof($bundled_product_attributes) == $loop) {
/** * Hide attributes if they correspond to filtered-out variations. * * @param string $output original output * @param array $attribute attribute data * @param array $values attribute values * @return string modified output */ public function bundled_item_attribute($output, $attribute, $values) { if ($attribute['is_variation']) { $variation_attribute_values = array(); $bundled_item = $this->get_bundled_item($this->listing_attributes_of); $bundled_item_variations = $bundled_item->get_product_variations(); if (empty($bundled_item_variations)) { return $output; } $attribute_key = 'attribute_' . sanitize_title($attribute['name']); // Find active attribute values from the bundled item variation data foreach ($bundled_item_variations as $variation_data) { if (isset($variation_data['attributes'][$attribute_key])) { $variation_attribute_values[] = $variation_data['attributes'][$attribute_key]; $variation_attribute_values = array_unique($variation_attribute_values); } } if (!empty($variation_attribute_values) && in_array('', $variation_attribute_values)) { return $output; } $attribute_name = $attribute['name']; $filtered_values = array(); if ($attribute['is_taxonomy']) { $product_terms = wc_bundles_get_product_terms($bundled_item->product_id, $attribute_name, array('fields' => 'all')); foreach ($product_terms as $product_term) { if (in_array($product_term->slug, $variation_attribute_values)) { $filtered_values[] = $product_term->name; } } return wpautop(wptexturize(implode(', ', $filtered_values))); } else { foreach ($values as $value) { if (in_array(sanitize_title($value), $variation_attribute_values)) { $filtered_values[] = $value; } } return wpautop(wptexturize(implode(', ', $filtered_values))); } } return $output; }