function wc_swatches_variation_attribute_options($args = array()) { $args = wp_parse_args(apply_filters('woocommerce_dropdown_variation_attribute_options_args', $args), array('options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'class' => '', 'show_option_none' => __('Choose an option', 'woocommerce'))); $options = $args['options']; $product = $args['product']; $attribute = $args['attribute']; $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute); $id = $args['id'] ? $args['id'] : sanitize_title($attribute); $config = new WC_Swatches_Attribute_Configuration_Object($product, $attribute); if ($config->get_type() == 'radio') { do_action('woocommerce_swatches_before_picker', $config); echo '<div id="picker_' . esc_attr($id) . '" class="radio-select select swatch-control">'; $args['hide'] = true; wc_core_dropdown_variation_attribute_options($args); wc_radio_variation_attribute_options($args); echo '</div>'; } elseif ($config->get_type() != 'default') { if ($config->get_label_layout() == 'label_above') { echo '<div class="attribute_' . $id . '_picker_label swatch-label"> </div>'; } do_action('woocommerce_swatches_before_picker', $config); echo '<div id="picker_' . esc_attr($id) . '" class="select swatch-control">'; $args['hide'] = true; wc_core_dropdown_variation_attribute_options($args); if (!empty($options)) { if ($product && taxonomy_exists($attribute)) { // Get terms if this is a taxonomy - ordered. We need the names too. $terms = wc_get_product_terms($product->id, $attribute, array('fields' => 'all')); foreach ($terms as $term) { if (in_array($term->slug, $options)) { if ($config->get_type() == 'term_options') { $swatch_term = new WC_Swatch_Term($config, $term->term_id, $attribute, $args['selected'] == $term->slug, $config->get_size()); } elseif ($config->get_type() == 'product_custom') { $swatch_term = new WC_Product_Swatch_Term($config, $term->term_id, $attribute, $args['selected'] == $term->slug, $config->get_size()); } do_action('woocommerce_swatches_before_picker_item', $swatch_term); echo $swatch_term->get_output(); do_action('woocommerce_swatches_after_picker_item', $swatch_term); } } } else { foreach ($options as $option) { // This handles < 2.4.0 bw compatibility where text attributes were not sanitized. $selected = sanitize_title($args['selected']) === $args['selected'] ? selected($args['selected'], sanitize_title($option), false) : selected($args['selected'], $option, false); $swatch_term = new WC_Product_Swatch_Term($config, $option, $name, $selected, $config->get_size()); do_action('woocommerce_swatches_before_picker_item', $swatch_term); echo $swatch_term->get_output(); do_action('woocommerce_swatches_after_picker_item', $swatch_term); } } } echo '</div>'; if ($config->get_label_layout() == 'label_below') { echo '<div class="attribute_' . $id . '_picker_label swatch-label"> </div>'; } } else { $args['hide'] = false; $args['class'] = $args['class'] .= (!empty($args['class']) ? ' ' : '') . 'wc-default-select'; wc_core_dropdown_variation_attribute_options($args); } }
<p class="stock out-of-stock"><?php _e('This product is currently out of stock and unavailable.', 'woocommerce'); ?> </p> <?php } else { ?> <div class="variations"> <?php foreach ($attributes as $attribute_name => $options) { ?> <?php $selected = isset($_REQUEST['attribute_' . sanitize_title($attribute_name)]) ? wc_clean($_REQUEST['attribute_' . sanitize_title($attribute_name)]) : $product->get_variation_default_attribute($attribute_name); wc_radio_variation_attribute_options(array('options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected)); ?> <?php } ?> </div> <?php do_action('woocommerce_before_add_to_cart_button'); ?> <div class="single_variation_wrap" style="display:none;"> <?php /** * woocommerce_before_single_variation Hook */