public function on_admin_head() { if (WC_Swatches_Compatibility::is_wc_version_gte_2_3()) { echo '<style type="text/css">'; echo '#' . $this->tab_id . ' { padding:10px; }'; echo '</style>'; return; } if (!function_exists('get_product')) { echo '<style type="text/css">'; echo '#woocommerce-product-data ul.product_data_tabs li.' . $this->tab_class . ' a {padding:9px 9px 9px 34px;line-height:16px;border-bottom:1px solid #d5d5d5;text-shadow:0 1px 1px #fff;color:#555;background:#ececec url(' . $this->tab_icon . ') no-repeat 9px 9px;}'; echo '#woocommerce-product-data ul.product_data_tabs li.' . $this->tab_class . '.active a{background-color:#f8f8f8;border-bottom:1px solid #f8f8f8;}'; echo '#' . $this->tab_id . ' { padding:10px; }'; echo '</style>'; } else { echo '<style type="text/css">'; if (WC_Swatches_Compatibility::is_wc_version_gte_2_1()) { echo '#woocommerce-product-data ul.product_data_tabs li.' . $this->tab_class . ' a {padding: 5px 5px 5px 20px;background:#F1F1F1 url(' . $this->tab_icon . ') no-repeat 5px 5px;}'; } else { echo '#woocommerce-product-data ul.product_data_tabs li.' . $this->tab_class . ' a {padding: 5px 5px 5px 28px;background:#F1F1F1 url(' . $this->tab_icon . ') no-repeat 5px 5px;}'; } echo '#woocommerce-product-data ul.product_data_tabs li.' . $this->tab_class . '.active a{ border-color: #DFDFDF;position: relative;background-color: #F8F8F8;color: #555;margin: 0 -1px 0 0;width: 113px;}'; echo '#woocommerce-product-data ul.product_data_tabs li.' . $this->tab_class . ' a:before { content:""; }'; echo '#' . $this->tab_id . ' { padding:10px; }'; echo '#swatches {width:99% !important;};'; echo '</style>'; } }
public function init_attribute_image_selector() { global $woocommerce, $_wp_additional_image_sizes; $screen = get_current_screen(); if (strpos($screen->id, 'pa_') !== false) { $this->taxonomy = $_REQUEST['taxonomy']; if (taxonomy_exists($_REQUEST['taxonomy'])) { $term_id = term_exists(isset($_REQUEST['tag_ID']) ? $_REQUEST['tag_ID'] : 0, $_REQUEST['taxonomy']); $term = 0; if ($term_id) { $term = get_term($term_id, $_REQUEST['taxonomy']); } $this->image_size = apply_filters('woocommerce_get_swatches_image_size', $this->image_size, $_REQUEST['taxonomy'], $term_id); } $the_size = isset($_wp_additional_image_sizes[$this->image_size]) ? $_wp_additional_image_sizes[$this->image_size] : $_wp_additional_image_sizes['shop_thumbnail']; if (isset($the_size['width']) && isset($the_size['height'])) { $this->image_width = $the_size['width']; $this->image_height = $the_size['height']; } else { $this->image_width = 32; $this->image_height = 32; } $attribute_taxonomies = WC_Swatches_Compatibility::wc_get_attribute_taxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { add_action('pa_' . $tax->attribute_name . '_add_form_fields', array(&$this, 'woocommerce_add_attribute_thumbnail_field')); add_action('pa_' . $tax->attribute_name . '_edit_form_fields', array(&$this, 'woocommerce_edit_attributre_thumbnail_field'), 10, 2); add_filter('manage_edit-pa_' . $tax->attribute_name . '_columns', array(&$this, 'woocommerce_product_attribute_columns')); add_filter('manage_pa_' . $tax->attribute_name . '_custom_column', array(&$this, 'woocommerce_product_attribute_column'), 10, 3); } } } }
public function picker() { ?> <!-- aqui imprime los colores --> <table class="variations-table" cellspacing="0"> <tbody> <?php $loop = 0; foreach ($this->attributes as $name => $options) { $loop++; $st_name = sanitize_title($name); $hashed_name = md5($st_name); $lookup_name = ''; if (isset($this->swatch_type_options[$hashed_name])) { $lookup_name = $hashed_name; } elseif (isset($this->swatch_type_options[$st_name])) { $lookup_name = $st_name; } ?> <tr> <td><label for="<?php echo $st_name; ?> "><?php echo WC_Swatches_Compatibility::wc_attribute_label($name); ?> </label></td> <td> <?php if (isset($this->swatch_type_options[$lookup_name])) { $picker_type = $this->swatch_type_options[$lookup_name]['type']; if ($picker_type == 'default') { $this->render_default($st_name, $options); } else { $this->render_picker($st_name, $options, $name); } } else { $this->render_default($st_name, $options); } ?> </td> </tr> <?php } ?> </tbody> </table> <?php }
public function on_admin_init() { if (isset($_REQUEST['taxonomy'])) { $this->taxonomy = $_REQUEST['taxonomy']; } $attribute_taxonomies = WC_Swatches_Compatibility::wc_get_attribute_taxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { add_action('pa_' . $tax->attribute_name . '_add_form_fields', array(&$this, 'woocommerce_add_attribute_thumbnail_field')); add_action('pa_' . $tax->attribute_name . '_edit_form_fields', array(&$this, 'woocommerce_edit_attributre_thumbnail_field'), 10, 2); add_filter('manage_edit-pa_' . $tax->attribute_name . '_columns', array(&$this, 'woocommerce_product_attribute_columns')); add_filter('manage_pa_' . $tax->attribute_name . '_custom_column', array(&$this, 'woocommerce_product_attribute_column'), 10, 3); } } }
private function do_javascript() { global $woocommerce; ob_start(); ?> jQuery(document).ready(function($) { var current_field_wrapper; window.send_to_editor_default = window.send_to_editor; jQuery('#swatches').on('click', '.upload_image_button, .remove_image_button', function() { var post_id = jQuery(this).attr('rel'); var parent = jQuery(this).parent(); current_field_wrapper = parent; if (jQuery(this).is('.remove_image_button')) { jQuery('.upload_image_id', current_field_wrapper).val(''); jQuery('img', current_field_wrapper).attr('src', '<?php echo woocommerce_placeholder_img_src(); ?> '); jQuery(this).removeClass('remove'); } else { window.send_to_editor = window.send_to_pidroduct; formfield = jQuery('.upload_image_id', parent).attr('name'); tb_show('', 'media-upload.php?&type=image&TB_iframe=true'); } return false; }); window.send_to_pidroduct = function(html) { jQuery('body').append('<div id="temp_image">' + html + '</div>'); var img = jQuery('#temp_image').find('img'); imgurl = img.attr('src'); imgclass = img.attr('class'); imgid = parseInt(imgclass.replace(/\D/g, ''), 10); jQuery('.upload_image_id', current_field_wrapper).val(imgid); jQuery('img', current_field_wrapper).attr('src', imgurl); var $preview = jQuery(current_field_wrapper).closest('div.sub_field').find('.swatch-wrapper'); jQuery('img', $preview).attr('src', imgurl); tb_remove(); jQuery('#temp_image').remove(); window.send_to_editor = window.send_to_editor_default; } }); <?php $javascript = ob_get_clean(); WC_Swatches_Compatibility::wc_enqueue_js($javascript); }
<div class="clear"></div><a id="variations_clear" href="#reset" style="display:none;"><?php _e('Reset selection', 'woocommerce'); ?> </a> </div> <?php do_action('woocommerce_before_add_to_cart_button'); ?> <div class="single_variation_wrap" style="display:none;"> <div class="single_variation"></div> <div class="variations_button"> <?php if (WC_Swatches_Compatibility::is_wc_version_gte_2_1()) { ?> <input type="hidden" name="add-to-cart" value="<?php echo $product->id; ?> " /> <?php } ?> <input type="hidden" name="product_id" value="<?php echo esc_attr($post->ID); ?> " /> <input type="hidden" name="variation_id" value="" />
function wc_swatches_on_plugin_loaded() { if (apply_filters('woocommerce_swatches_load_previous_version', false) === false && WC_Swatches_Compatibility::is_wc_version_gte_2_4()) { class WC_SwatchesPlugin { private $product_attribute_images; public function __construct() { define('WC_SWATCHES_VERSION', '2.0.1'); require 'woocommerce-swatches-template-functions.php'; require 'classes/class-wc-swatch-term.php'; require 'classes/class-wc-swatch-product-term.php'; require 'classes/class-wc-swatches-product-attribute-images.php'; require 'classes/class-wc-ex-product-data-tab.php'; require 'classes/class-wc-swatches-product-data-tab.php'; require 'classes/class-wc-swatch-attribute-configuration.php'; require 'classes/class-wc-swatches-ajax-handler.php'; add_action('init', array(&$this, 'on_init')); add_action('wc_quick_view_enqueue_scripts', array($this, 'on_enqueue_scripts')); add_action('wp_enqueue_scripts', array(&$this, 'on_enqueue_scripts')); add_action('admin_head', array(&$this, 'on_enqueue_scripts')); $this->product_attribute_images = new WC_Swatches_Product_Attribute_Images('swatches_id', 'swatches_image_size'); $this->product_data_tab = new WC_Swatches_Product_Data_Tab(); //Swatch Image Size Settings add_filter('woocommerce_catalog_settings', array(&$this, 'swatches_image_size_setting')); // pre WC 2.1 add_filter('woocommerce_product_settings', array(&$this, 'swatches_image_size_setting')); // WC 2.1+ add_filter('woocommerce_get_image_size_swatches', array($this, 'get_image_size_swatches')); } public function on_init() { global $woocommerce; $image_size = get_option('swatches_image_size', array()); $size = array(); $size['width'] = isset($image_size['width']) && !empty($image_size['width']) ? $image_size['width'] : '32'; $size['height'] = isset($image_size['height']) && !empty($image_size['height']) ? $image_size['height'] : '32'; $size['crop'] = isset($image_size['crop']) ? $image_size['crop'] : 1; $image_size = apply_filters('woocommerce_get_image_size_swatches_image_size', $size); add_image_size('swatches_image_size', apply_filters('woocommerce_swatches_size_width_default', $image_size['width']), apply_filters('woocommerce_swatches_size_height_default', $image_size['height']), $image_size['crop']); } public function on_enqueue_scripts() { global $pagenow, $wp_scripts; if (!is_admin()) { wp_enqueue_style('swatches-and-photos', $this->plugin_url() . '/assets/css/swatches-and-photos.css', array(), WC_SWATCHES_VERSION); wp_enqueue_script('swatches-and-photos', $this->plugin_url() . '/assets/js/swatches-and-photos.js', array('jquery'), WC_SWATCHES_VERSION, true); $data = array('ajax_url' => admin_url('admin-ajax.php')); wp_localize_script('swatches-and-photos', 'wc_swatches_params', $data); } if (is_admin() && ($pagenow == 'post-new.php' || $pagenow == 'post.php' || $pagenow == 'edit.php' || 'edit-tags.php')) { wp_enqueue_media(); wp_enqueue_style('swatches-and-photos', $this->plugin_url() . '/assets/css/swatches-and-photos.css'); wp_enqueue_script('swatches-and-photos-admin', $this->plugin_url() . '/assets/js/swatches-and-photos-admin.js', array('jquery'), '1.0', true); wp_enqueue_style('colourpicker', $this->plugin_url() . '/assets/css/colorpicker.css'); wp_enqueue_script('colourpicker', $this->plugin_url() . '/assets/js/colorpicker.js', array('jquery')); $data = array('placeholder_img_src' => apply_filters('woocommerce_placeholder_img_src', WC()->plugin_url() . '/assets/images/placeholder.png')); wp_localize_script('swatches-and-photos-admin', 'wc_swatches_params', $data); } } public function plugin_url() { return untrailingslashit(plugin_dir_url(__FILE__)); } public function plugin_dir() { return plugin_dir_path(__FILE__); } public function swatches_image_size_setting($settings) { $setting = array('name' => __('Swatches and Photos', 'wc_swatches_and_photos'), 'desc' => __('The default size for color swatches and photos.', 'wc_swatches_and_photos'), 'id' => 'swatches_image_size', 'css' => '', 'type' => 'image_width', 'std' => '32', 'desc_tip' => true, 'default' => array('crop' => true, 'width' => 32, 'height' => 32)); $index = count($settings) - 1; $settings[$index + 1] = $settings[$index]; $settings[$index] = $setting; return $settings; } public function get_image_size_swatches($size) { $image_size = get_option('swatches_image_size', array()); $size = array(); $size['width'] = isset($image_size['width']) && !empty($image_size['width']) ? $image_size['width'] : '32'; $size['height'] = isset($image_size['height']) && !empty($image_size['height']) ? $image_size['height'] : '32'; $size['crop'] = isset($image_size['crop']) ? 1 : 0; $image_size = apply_filters('woocommerce_get_image_size_swatches_image_size', $size); //Need to remove the filter because woocommerce will disable the input field. remove_filter('woocommerce_get_image_size_swatches', array($this, 'get_image_size_swatches')); return $image_size; } } $GLOBALS['woocommerce_swatches'] = new WC_SwatchesPlugin(); } else { require 'back_compat_less_24/woocommerce-swatches.php'; } }
function woocommerce_swatches_get_variation_form_args() { global $woocommerce, $product, $post; $is_wc_24 = version_compare(WC_Swatches_Compatibility::get_wc_version(), '2.4.0', '>='); $is_product_wc_24 = version_compare(get_post_meta($product->id, '_product_version', true), '2.4.0', '>='); $attributes = $product->get_variation_attributes(); $attributes_renamed = array(); $hashed_attributes = array(); $attribute_map = array(); foreach ($attributes as $attribute => $values) { $attributes_renamed['attribute_' . sanitize_title($attribute)] = array_values(array_map('md5', array_map('sanitize_title', array_map('strtolower', $values)))); $hashed_attributes[$attribute] = array_map('md5', $values); foreach ($values as $value) { if ($is_product_wc_24) { $attribute_map['attribute_' . sanitize_title($attribute)][md5(sanitize_title($value))] = $value; } else { if ($is_wc_24) { $attribute_map['attribute_' . sanitize_title($attribute)][md5(sanitize_title($value))] = $value; } else { $attribute_map['attribute_' . sanitize_title($attribute)][md5(sanitize_title($value))] = sanitize_title($value); } } } } $default_attributes = (array) maybe_unserialize($product->get_variation_default_attributes()); $selected_attributes = apply_filters('woocommerce_product_default_attributes', $default_attributes); $selected_attributes = array(); foreach ($default_attributes as $sk => $s) { $selected_attributes[md5($sk)] = $s; } // Put available variations into an array and put in a Javascript variable (JSON encoded) $available_variations = array(); $available_variations_flat = array(); foreach ($product->get_children() as $child_id) { $variation = $product->get_child($child_id); if ($variation instanceof WC_Product_Variation) { if (get_post_status($variation->get_variation_id()) != 'publish') { continue; } // Disabled if (empty($variation->variation_id) || 'yes' === get_option('woocommerce_hide_out_of_stock_items') && !$variation->is_in_stock()) { continue; } $variation_attributes = $variation->get_variation_attributes(); $hva = array(); foreach ($variation_attributes as $vak => $va) { if (!empty($va)) { if ($is_product_wc_24) { $hva[$vak] = md5(sanitize_title($va)); } else { if ($is_wc_24 && !$is_product_wc_24) { $hva[$vak] = md5(sanitize_title($va)); } else { $hva[$vak] = md5($va); } } } else { $hva[$vak] = ''; } } $available_variations_flat[] = $hva; } } $av = $product->get_available_variations(); $result = array('available_variations' => $av, 'available_variations_flat' => $available_variations_flat, 'attributes' => $hashed_attributes, 'attributes_renamed' => $attributes_renamed, 'selected_attributes' => $selected_attributes, 'variations_map' => $attribute_map); return $result; }
public function render_product_tab_content() { global $woocommerce, $post; global $_wp_additional_image_sizes; add_filter('woocommerce_variation_is_visible', array($this, 'return_true')); $post_id = $post->ID; if (function_exists('get_product')) { $product = get_product($post->ID); } else { $product = new WC_Product($post->ID); } $product_type_array = array('variable', 'variable-subscription'); if (!in_array($product->product_type, $product_type_array)) { return; } $swatch_type_options = get_post_meta($post_id, '_swatch_type_options', true); $swatch_type = get_post_meta($post_id, '_swatch_type', true); $swatch_size = get_post_meta($post_id, '_swatch_size', true); if (!$swatch_type_options) { $swatch_type_options = array(); } if (!$swatch_type) { $swatch_type = 'standard'; } if (!$swatch_size) { $swatch_size = 'swatches_image_size'; } echo '<div class="options_group">'; ?> <div class="fields_header"> <table class="wcsap widefat"> <thead> <th class="attribute_swatch_label"> <?php _e('Product Attribute Name', 'wc_swatches_and_photos'); ?> </th> <th class="attribute_swatch_type"> <?php _e('Attribute Control Type', 'wc_swatches_and_photos'); ?> </th> </thead> </table> </div> <div class="fields"> <?php $woocommerce_taxonomies = WC_Swatches_Compatibility::wc_get_attribute_taxonomies(); $woocommerce_taxonomy_infos = array(); foreach ($woocommerce_taxonomies as $tax) { $woocommerce_taxonomy_infos[WC_Swatches_Compatibility::wc_attribute_taxonomy_name($tax->attribute_name)] = $tax; } $tax = null; $attributes = $product->get_variation_attributes(); //Attributes configured on this product already. if ($attributes && count($attributes)) { $attribute_names = array_keys($attributes); foreach ($attribute_names as $name) { $key = md5(sanitize_title($name)); $old_key = sanitize_title($name); $key_attr = md5(str_replace('-', '_', sanitize_title($name))); $current_is_taxonomy = taxonomy_exists($name); $current_type = 'default'; $current_type_description = 'None'; $current_size = 'swatches_image_size'; $current_layout = 'default'; $current_size_height = '32'; $current_size_width = '32'; $current_label = 'Unknown'; $current_options = false; if (isset($swatch_type_options[$key])) { $current_options = $swatch_type_options[$key]; } elseif (isset($swatch_type_options[$old_key])) { $current_options = $swatch_type_options[$old_key]; } if ($current_options) { $current_size = $current_options['size']; $current_type = $current_options['type']; $current_layout = isset($current_options['layout']) ? $current_options['layout'] : 'default'; if ($current_type != 'default' && $current_type != 'radio') { $current_type_description = $current_type == 'term_options' ? __('Taxonomy Colors and Images', 'wc_swatches_and_photos') : __('Custom Product Colors and Images', 'wc_swatches_and_photos'); } elseif ($current_type == 'radio') { $current_type_description = __('Radio Buttons', 'wc_swatches_and_photos'); } } $the_size = isset($_wp_additional_image_sizes[$current_size]) ? $_wp_additional_image_sizes[$current_size] : $_wp_additional_image_sizes['swatches_image_size']; if (isset($the_size['width']) && isset($the_size['height'])) { $current_size_width = $the_size['width']; $current_size_height = $the_size['height']; } else { $current_size_width = 32; $current_size_height = 32; } $attribute_terms = array(); if (taxonomy_exists($name)) { $tax = get_taxonomy($name); $woocommerce_taxonomy = $woocommerce_taxonomy_infos[$name]; $current_label = isset($woocommerce_taxonomy->attribute_label) && !empty($woocommerce_taxonomy->attribute_label) ? $woocommerce_taxonomy->attribute_label : $woocommerce_taxonomy->attribute_name; $terms = get_terms($name, array('hide_empty' => false)); $selected_terms = isset($attributes[$name]) ? $attributes[$name] : array(); foreach ($terms as $term) { if (in_array($term->slug, $selected_terms)) { $attribute_terms[] = array('id' => md5($term->slug), 'label' => $term->name, 'old_id' => $term->slug); } } } else { $current_label = esc_html($name); foreach ($attributes[$name] as $term) { $attribute_terms[] = array('id' => md5(sanitize_title(strtolower($term))), 'label' => esc_html($term), 'old_id' => esc_attr(sanitize_title($term))); } } ?> <div class="field"> <div class="wcsap_field_meta"> <table class="wcsap widefat"> <tbody> <tr> <td class="attribute_swatch_label"> <strong><a class="wcsap_edit_field row-title" href="javascript:;"><?php echo $current_label; ?> </a></strong> </td> <td class="attribute_swatch_type"> <?php echo $current_type_description; ?> </td> </tr> </tbody> </table> </div> <div class="field_form_mask"> <div class="field_form"> <table class="wcsap_input widefat wcsap_field_form_table"> <tbody> <tr class="attribute_swatch_type"> <td class="label"> <label for="_swatch_type_options_<?php echo $key_attr; ?> _type">Type</label> </td> <td> <select class="_swatch_type_options_type" id="_swatch_type_options_<?php echo $key_attr; ?> _type" name="_swatch_type_options[<?php echo $key; ?> ][type]"> <option <?php selected($current_type, 'default'); ?> value="default">None</option> <?php if ($current_is_taxonomy) { ?> <option <?php selected($current_type, 'term_options'); ?> value="term_options"><?php _e('Taxonomy Colors and Images', 'wc_swatches_and_photos'); ?> </option> <?php } ?> <option <?php selected($current_type, 'product_custom'); ?> value="product_custom"><?php _e('Custom Colors and Images', 'wc_swatches_and_photos'); ?> </option> <option <?php selected($current_type, 'radio'); ?> value="radio"><?php _e('Radio Buttons', 'wc_swatches_and_photos'); ?> </option> </select> </td> </tr> <tr class="field_option field_option_product_custom field_option_term_options" style="<?php echo $current_type != 'product_custom' && $current_type != 'term_options' ? 'display:none;' : ''; ?> "> <td class="label"> <label for="_swatch_type_options_<?php echo $key_attr; ?> _layout">Layout</label> </td> <td> <?php $layouts = array('default' => __('No Label', 'wc_swatches_and_photos'), 'label_above' => __('Show label above', 'wc_swatches_and_photos'), 'label_below' => __('Show label below')); ?> <select name="_swatch_type_options[<?php echo $key; ?> ][layout]"> <?php foreach ($layouts as $layout => $layout_name) { ?> <option <?php selected($current_layout, $layout); ?> value="<?php echo $layout; ?> "><?php echo $layout_name; ?> </option> <?php } ?> </select> </td> </tr> <tr class="field_option field_option_product_custom" style="<?php echo $current_type != 'product_custom' ? 'display:none;' : ''; ?> "> <td class="label"> <label for="_swatch_type_options_<?php echo $key_attr; ?> _size">Size</label> </td> <td> <?php $image_sizes = get_intermediate_image_sizes(); ?> <select id="_swatch_type_options_pa_color_size" name="_swatch_type_options[<?php echo $key; ?> ][size]"> <?php foreach ($image_sizes as $size) { ?> <option <?php selected($current_size, $size); ?> value="<?php echo $size; ?> "><?php echo $size; ?> </option> <?php } ?> </select> </td> </tr> <tr class="field_option field_option_term_default" style="<?php echo $current_type != 'default' ? 'display:none;' : ''; ?> "> <td class="label"> </td> <td> <p> <?php _e('WooCommerce default select boxes will be used for this product attribute', 'wc_swatches_and_photos'); ?> </p> </td> </tr> <tr class="field_option field_option_term_options" style="<?php echo $current_type != 'term_options' ? 'display:none;' : ''; ?> "> <td class="label"> </td> <td> <p> <?php printf(__('The color swatch and image configuration will be used from the %s taxonomy. Navigate to Products -> Attributes to edit the shared swatches and images for this product attribute.', 'wc_swatches_and_photos'), $current_label); ?> </p> </td> </tr> <tr class="field_option field_option_product_custom" style="<?php echo $current_type != 'product_custom' ? 'display:none;' : ''; ?> "> <td class="label"> <label>Attribute Configuration</label> </td> <td> <div class="product_custom"> <div class="fields_header"> <table class="wcsap widefat"> <thead> <th class="attribute_swatch_preview"> <?php _e('Preview', 'wc_swatches_and_photos'); ?> </th> <th class="attribute_swatch_label"> <?php _e('Attribute', 'wc_swatches_and_photos'); ?> </th> <th class="attribute_swatch_type"> <?php _e('Type', 'wc_swatches_and_photos'); ?> </th> </thead> </table> </div> <div class="fields"> <?php foreach ($attribute_terms as $attribute_term) { ?> <?php $attribute_term['id'] = $attribute_term['id']; $current_attribute_type = 'color'; $current_attribute_color = '#FFFFFF'; $current_attribute_image_src = WC_Swatches_Compatibility::wc_placeholder_img_src(); $current_attribute_image_id = 0; $current_attribute_options = false; if (isset($current_options['attributes'][$attribute_term['id']])) { $current_attribute_options = isset($current_options['attributes'][$attribute_term['id']]) ? $current_options['attributes'][$attribute_term['id']] : false; } elseif (isset($current_options['attributes'][$attribute_term['old_id']])) { $current_attribute_options = isset($current_options['attributes'][$attribute_term['old_id']]) ? $current_options['attributes'][$attribute_term['old_id']] : false; } if ($current_attribute_options) { $current_attribute_type = $current_attribute_options['type']; $current_attribute_color = $current_attribute_options['color']; $current_attribute_image_id = $current_attribute_options['image']; if ($current_attribute_image_id) { $current_attribute_image_src = wp_get_attachment_image_src($current_attribute_image_id, $current_size); $current_attribute_image_src = $current_attribute_image_src[0]; } } elseif ($current_is_taxonomy) { } ?> <div class="sub_field field"> <div class="wcsap_field_meta"> <table class="wcsap widefat"> <tbody> <td class="attribute_swatch_preview"> <div class="select-option swatch-wrapper"> <a id="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo $attribute_term['id']; ?> _color_preview_image" href="javascript:;" class="image" style="width:16px;height:16px;<?php echo $current_attribute_type == 'image' ? '' : 'display:none;'; ?> "> <img src="<?php echo $current_attribute_image_src; ?> " class="wp-post-image" width="16px" height="16px" /> </a> <a id="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo $attribute_term['id']; ?> _color_preview_swatch" href="javascript:;" class="swatch" style="text-indent:-9999px;width:16px;height:16px;background-color:<?php echo $current_attribute_color; ?> ;<?php echo $current_attribute_type == 'color' ? '' : 'display:none;'; ?> "><?php echo $attribute_term['label']; ?> </a> </div> </td> <td class="attribute_swatch_label"> <strong><a class="wcsap_edit_field row-title" href="javascript:;"><?php echo $attribute_term['label']; ?> </a></strong> </td> <td class="attribute_swatch_type"> <?php echo $current_attribute_type == 'image' ? __('Image', 'wc_swatches_and_photos') : __('Color Swatch', 'wc_swatches_and_photos'); ?> </td> <tbody> </table> </div> <div class="field_form_mask"> <div class="field_form"> <table class="wcsap_input widefat"> <tbody> <tr class="attribute_swatch_type"> <td class="label"> <label for="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo esc_attr($attribute_term['id']); ?> "> <?php _e('Attribute Color or Image', 'wc_swatches_and_photos'); ?> </label> </td> <td> <select class="_swatch_type_options_attribute_type" id="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo esc_attr($attribute_term['id']); ?> _type" name="_swatch_type_options[<?php echo $key; ?> ][attributes][<?php echo esc_attr($attribute_term['id']); ?> ][type]"> <option <?php selected($current_attribute_type, 'color'); ?> value="color">Color</option> <option <?php selected($current_attribute_type, 'image'); ?> value="image">Image</option> </select> </td> </tr> <tr class="field_option field_option_color" style="<?php echo $current_attribute_type == 'color' ? '' : 'display:none;'; ?> "> <td class="label"> <label><?php _e('Color', 'wc_swatches_and_photos'); ?> </label> </td> <td class="section-color-swatch"> <div id="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo $attribute_term['id']; ?> _color_picker" class="colorSelector"><div></div></div> <input class="woo-color" id="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo $attribute_term['id']; ?> _color" type="text" class="text" name="_swatch_type_options[<?php echo $key; ?> ][attributes][<?php echo esc_attr($attribute_term['id']); ?> ][color]" value="<?php echo $current_attribute_color; ?> " /> </td> </tr> <tr class="field_option field_option_image" style="<?php echo $current_attribute_type == 'image' ? '' : 'display:none;'; ?> "> <td class="label"> <label><?php _e('Image', 'wc_swatches_and_photos'); ?> </label> </td> <td> <div style="line-height:60px;"> <div id="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo $attribute_term['id']; ?> _image_thumbnail" style="float:left;margin-right:10px;"> <img src="<?php echo $current_attribute_image_src; ?> " alt="<?php _e('Thumbnail Preview', 'wc_swatches_and_photos'); ?> " class="wp-post-image swatch-photopa_colour_swatches_id" width="<?php echo '16px'; ?> " height="<?php echo '16px'; ?> "> </div> <input class="upload_image_id" type="hidden" id="_swatch_type_options_<?php echo $key_attr; ?> _<?php echo $attribute_term['id']; ?> _image" name="_swatch_type_options[<?php echo $key; ?> ][attributes][<?php echo esc_attr($attribute_term['id']); ?> ][image]" value="<?php echo $current_attribute_image_id; ?> " /> <button type="submit" class="upload_swatch_image_button button" rel="<?php echo $post_id; ?> "><?php _e('Upload/Add image', 'woocommerce'); ?> </button> <button type="submit" class="remove_swatch_image_button button" rel="<?php echo $post_id; ?> "><?php _e('Remove image', 'woocommerce'); ?> </button> </div> </td> </tr> </tbody> </table> </div> </div> </div> <?php } ?> </div> </div> </td> </tr> </tbody> </table> </div> </div> </div> <?php } } else { echo '<p>' . __('Add a at least one attribute / variation combination to this product that has been configured with color swatches or photos. After you add the attributes from the "Attributes" tab and create a variation, save the product and you will see the option to configure the swatch or photo picker here.', 'wc_swatches_and_photos') . '</p>'; } ?> </div> <?php echo '</div>'; parent::render_product_tab_content(); remove_filter('woocommerce_variation_is_visible', array($this, 'return_true')); }
$loop++; $st_name = sanitize_title($name); $hashed_name = md5($st_name); $lookup_name = ''; if (isset($picker->swatch_type_options[$hashed_name])) { $lookup_name = $hashed_name; } elseif (isset($picker->swatch_type_options[$st_name])) { $lookup_name = $st_name; } ?> <tr> <td class="label"><label for="<?php echo $st_name; ?> "><?php echo WC_Swatches_Compatibility::wc_attribute_label($name); ?> </label></td> <td> <?php if (isset($picker->swatch_type_options[$lookup_name])) { $picker_type = $picker->swatch_type_options[$lookup_name]['type']; if ($picker_type == 'default') { $picker->render_default($st_name, $options); } else { $picker->render_picker($st_name, $options, $name); } } else { $picker->render_default($st_name, $options); } ?>