Exemplo n.º 1
2
function woocommerce_subcategory_thumbnail($category)
{
    // Vars
    $title = get_the_title();
    $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
    $attachment_url = wp_get_attachment_url($thumbnail_id);
    $width = wpex_option('woo_cat_entry_width', '9999');
    $height = wpex_option('woo_cat_entry_height', '9999');
    $crop = $height == '9999' ? false : true;
    // Echo Image
    echo '<img src="' . aq_resize($attachment_url, $width, $height, $crop) . '" alt="' . $title . '" />';
}
 /**
  * List multiple brands shortcode
  *
  * @access public
  * @param array $atts
  * @return string
  */
 public static function brands($atts)
 {
     global $woocommerce_loop;
     if (empty($atts)) {
         return '';
     }
     extract(shortcode_atts(array('orderby' => 'title', 'columns' => '6', 'order' => 'asc', 'per_page' => '6', 'carousel' => 'true'), $atts));
     $brands = get_categories(array('hide_empty' => 0, 'taxonomy' => 'product_brand', 'orderby' => $orderby, 'order' => $order, 'number' => $per_page));
     $output = '';
     $columns = intval($columns);
     $columns = 12 / $columns;
     foreach ($brands as $brand) {
         $thumbnail_id = get_woocommerce_term_meta($brand->term_id, 'thumbnail_id');
         $image_src = wp_get_attachment_image_src($thumbnail_id, 'full');
         $brand_link = get_term_link($brand, 'product_brand');
         $brand_item = '<div class="brand-item">';
         $brand_item .= "\t" . '<a href="' . $brand_link . '"><img alt="' . $brand->cat_name . '" src="' . $image_src[0] . '" width="144" height="36" /></a>';
         $brand_item .= '</div>';
         if ($carousel === 'false') {
             $output .= '<div class="col-xs-12 col-sm-' . $columns . '">' . $brand_item . '</div>';
         } else {
             $output .= $brand_item;
         }
     }
     return $output;
 }
function ml_get_categories_with_thumbnails_loop()
{
    $taxonomy = 'product_cat';
    $orderby = 'name';
    $show_count = 0;
    // 1 for yes, 0 for no
    $pad_counts = 0;
    // 1 for yes, 0 for no
    $hierarchical = 1;
    // 1 for yes, 0 for no
    $title = '';
    $empty = 0;
    $args = array('taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty);
    $all_categories = get_categories($args);
    foreach ($all_categories as $cat) {
        if ($cat->category_parent == 0) {
            $category_id = $cat->term_id;
            echo '<br /><a href="' . get_term_link($cat->slug, 'product_cat') . '">' . $cat->name . '</a>';
            $thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true);
            $image = wp_get_attachment_url($thumbnail_id);
            if ($image) {
                echo '<img src="' . $image . '" alt="" />';
            }
        }
    }
}
Exemplo n.º 4
0
    /**
     * extra fields while editing category.
     *
     * @author Lukas Juhas
     * @date   2016-02-04
     *
     * @param [type] $term [description]
     *
     * @return [type] [description]
     */
    public function edit_category_fields($term)
    {
        $wcl_cat_password_protected = absint(get_woocommerce_term_meta($term->term_id, 'wcl_cat_password_protected', true));
        $wcl_cat_password = get_woocommerce_term_meta($term->term_id, 'wcl_cat_password', true);
        ?>
        <tr class="form-field">
            <th scope="row" valign="top">
                Password Protection
            </th>
            <td>
                <label id="wcl_cat_password_protected">
                    <input type="checkbox" name="wcl_cat_password_protected" value="1" <?php 
        if ($wcl_cat_password_protected) {
            echo 'checked="checked"';
        }
        ?>
 />
                    <?php 
        _e('Password Protected', WCL_PLUGIN_DOMAIN);
        ?>
                </label>
                <div class="clear"></div>
                <div id="wcl_cat_password" style="<?php 
        if (!$wcl_cat_password_protected) {
            echo 'display:none;';
        }
        ?>
 float: left;">
                  <label>
                      <?php 
        _e('Password:'******'disabled="disabled"';
        }
        ?>
 required="required" />
                  </label>
                </div>
                <script>
                    jQuery('#wcl_cat_password_protected').on('click', function() {
                        var $checked = jQuery('input[name="wcl_cat_password_protected"]:checkbox:checked').length > 0;
                        if($checked) {
                          jQuery('#wcl_cat_password').find('input').prop('disabled', false);
                          jQuery('#wcl_cat_password').slideDown();
                        } else {
                          jQuery('#wcl_cat_password').find('input').prop('disabled', true);
                          jQuery('#wcl_cat_password').slideUp();
                        }
                    });
                </script>
                <div class="clear"></div>
            </td>
        </tr>
      <?php 
    }
Exemplo n.º 5
0
 public function on_init()
 {
     global $woocommerce, $_wp_additional_image_sizes;
     $this->init_size($this->size);
     $type = get_woocommerce_term_meta($this->term_id, $this->meta_key() . '_type', true);
     $color = get_woocommerce_term_meta($this->term_id, $this->meta_key() . '_color', true);
     $this->thumbnail_id = get_woocommerce_term_meta($this->term_id, $this->meta_key() . '_photo', true);
     $this->type = $type;
     $this->thumbnail_src = $woocommerce->plugin_url() . '/assets/images/placeholder.png';
     $this->color = '#FFFFFF';
     if ($type == 'photo') {
         if ($this->thumbnail_id) {
             $imgsrc = wp_get_attachment_image_src($this->thumbnail_id, $this->size);
             if ($imgsrc && is_array($imgsrc)) {
                 $this->thumbnail_src = current($imgsrc);
             } else {
                 $this->thumbnail_src = $woocommerce->plugin_url() . '/assets/images/placeholder.png';
             }
         } else {
             $this->thumbnail_src = $woocommerce->plugin_url() . '/assets/images/placeholder.png';
         }
     } elseif ($type == 'color') {
         $this->color = $color;
     }
 }
 /**
  * Prepare a single product category output for response.
  *
  * @param WP_Term $item Term object.
  * @param WP_REST_Request $request
  * @return WP_REST_Response $response
  */
 public function prepare_item_for_response($item, $request)
 {
     // Get category display type.
     $display_type = get_woocommerce_term_meta($item->term_id, 'display_type');
     // Get category order.
     $menu_order = get_woocommerce_term_meta($item->term_id, 'order');
     $data = array('id' => (int) $item->term_id, 'name' => $item->name, 'slug' => $item->slug, 'parent' => (int) $item->parent, 'description' => $item->description, 'display' => $display_type ? $display_type : 'default', 'image' => array(), 'menu_order' => (int) $menu_order, 'count' => (int) $item->count);
     // Get category image.
     if ($image_id = get_woocommerce_term_meta($item->term_id, 'thumbnail_id')) {
         $attachment = get_post($image_id);
         $data['image'] = array('id' => (int) $image_id, 'date_created' => wc_rest_prepare_date_response($attachment->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified_gmt), 'src' => wp_get_attachment_url($image_id), 'title' => get_the_title($attachment), 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true));
     }
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($item, $request));
     /**
      * Filter a term item returned from the API.
      *
      * Allows modification of the term data right before it is returned.
      *
      * @param WP_REST_Response  $response  The response object.
      * @param object            $item      The original term object.
      * @param WP_REST_Request   $request   Request used to generate the response.
      */
     return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
 }
Exemplo n.º 7
0
/**
 * get thumbnail product brand by id
 * @param int $brand_id
 * @param string $size
 */
function dhwc_get_product_brand_thumbnail_url($brand_id, $size = 'full')
{
    $thumbnail_id = get_woocommerce_term_meta($brand_id, 'thumbnail_id', true);
    if ($thumbnail_id) {
        return current(wp_get_attachment_image_src($thumbnail_id, $size));
    }
}
 /**
  * Renders our  panel.
  */
 public static function panel($tag = null)
 {
     global $post, $wpdb;
     global $wp_roles;
     if (class_exists('WP_Roles')) {
         if (!isset($wp_roles)) {
             $wp_roles = new WP_Roles();
         }
     }
     $output = '';
     $term_id = isset($tag->term_id) ? $tag->term_id : null;
     $output .= '<div class="form-field">';
     $pricing_options = array();
     foreach ($wp_roles->role_objects as $role) {
         $pricing_options['value_' . $role->name] = get_woocommerce_term_meta($term_id, 'role_pricing_value_' . $role->name, true);
     }
     $output .= '<div class="options_role"  style="border: 1px solid #ccc; padding:10px;">';
     $output .= '<h4>' . __('Woocommerce Role Pricing', WOO_ROLE_PRICING_DOMAIN) . '</h4>';
     $output .= '<p class="description">';
     $output .= __('Leave empty if no custom role discount should be applied to this category.', WOO_ROLE_PRICING_DOMAIN);
     $output .= '</p>';
     foreach ($wp_roles->role_objects as $role) {
         $output .= '<p>';
         $output .= '<label style="width:120px;float:left;">' . ucwords($role->name) . '</label>';
         $output .= '<input type="text" style="width:auto;" size="10" name="role_pricing_value_' . $role->name . '" value="' . @$pricing_options['value_' . $role->name] . '" />';
         $output .= '</p>';
     }
     $output .= '</div>';
     $output .= '</div>';
     // .form-field
     echo $output;
 }
Exemplo n.º 9
0
function wc1c_manage_taxonomy_custom_column($columns, $column, $id)
{
    if ($column == 'wc1c_guid') {
        $guid = get_woocommerce_term_meta($id, 'wc1c_guid');
        list($taxonomy, $guid) = explode('::', $guid);
        $columns .= $guid ? "<small>{$guid}</small>" : '<span class="na">–</span>';
    }
    return $columns;
}
Exemplo n.º 10
0
 public static function get_categories()
 {
     global $wp_query;
     $defaults = array('before' => '', 'after' => '', 'force_display' => false);
     $args = array();
     $args = wp_parse_args($args, $defaults);
     extract($args);
     $term = get_queried_object();
     $parent_id = empty($term->term_id) ? 0 : $term->term_id;
     if (is_product_category()) {
         $display_type = get_woocommerce_term_meta($term->term_id, 'display_type', true);
         switch ($display_type) {
             case 'products':
                 return;
                 break;
             case '':
                 if (get_option('woocommerce_category_archive_display') == '') {
                     return;
                 }
                 break;
         }
     }
     $product_categories = get_categories(apply_filters('woocommerce_product_subcategories_args', array('parent' => $parent_id, 'menu_order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'taxonomy' => 'product_cat', 'pad_counts' => 1)));
     if (!apply_filters('woocommerce_product_subcategories_hide_empty', false)) {
         $product_categories = wp_list_filter($product_categories, array('count' => 0), 'NOT');
     }
     if ($product_categories) {
         echo $before;
         foreach ($product_categories as $category) {
             wc_get_template('content-product_cat.php', array('category' => $category));
         }
         if (is_product_category()) {
             $display_type = get_woocommerce_term_meta($term->term_id, 'display_type', true);
             switch ($display_type) {
                 case 'subcategories':
                     $wp_query->post_count = 0;
                     $wp_query->max_num_pages = 0;
                     break;
                 case '':
                     if (get_option('woocommerce_category_archive_display') == 'subcategories') {
                         $wp_query->post_count = 0;
                         $wp_query->max_num_pages = 0;
                     }
                     break;
             }
         }
         if (is_shop() && get_option('woocommerce_shop_page_display') == 'subcategories') {
             $wp_query->post_count = 0;
             $wp_query->max_num_pages = 0;
         }
         echo $after;
         return true;
     }
 }
/**
 * ID list of categories that are locked
 * @author Lukas Juhas
 * @date   2016-02-08
 * @return [type]     [description]
 */
function wcl_get_locked_categories()
{
    $locked = array();
    $shop_terms = get_terms('product_cat');
    foreach ($shop_terms as $term) {
        $is_password_protected = get_woocommerce_term_meta($term->term_id, 'wcl_cat_password_protected');
        if ($is_password_protected) {
            $locked[] = $term->term_id;
        }
    }
    return $locked;
}
Exemplo n.º 12
0
function woocommerce_category_image()
{
    if (is_product_category()) {
        global $wp_query;
        $cat = $wp_query->get_queried_object();
        $thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true);
        $image = wp_get_attachment_url($thumbnail_id);
        if ($image) {
            echo '<img src="' . $image . '" alt="" class="img-responsive" />';
        }
    }
}
Exemplo n.º 13
0
    function widget($args, $instance)
    {
        extract($args);
        $title = $instance['title'];
        echo $before_widget;
        if (!$title == '') {
            echo $before_title;
            echo $title;
            echo $after_title;
        }
        $current_term = get_queried_object();
        $args = array('hide_empty' => false);
        $terms = get_terms('brand', $args);
        $count = count($terms);
        $i = 0;
        if ($count > 0) {
            ?>
			<ul>
				<?php 
            foreach ($terms as $term) {
                $i++;
                $curr = false;
                $thumbnail_id = absint(get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true));
                if (isset($current_term->term_id) && $current_term->term_id == $term->term_id) {
                    $curr = true;
                }
                ?>
				        	<li>
				        		<a href="<?php 
                echo get_term_link($term);
                ?>
" title="<?php 
                echo sprintf(__('View all products from %s', ETHEME_DOMAIN), $term->name);
                ?>
"><?php 
                if ($curr) {
                    echo '<strong>';
                }
                echo $term->name;
                if ($curr) {
                    echo '</strong>';
                }
                ?>
</a>
				        	</li>
						<?php 
            }
            ?>
			</ul>
			<?php 
        }
        echo $after_widget;
    }
Exemplo n.º 14
0
/**
 * Overrides the default woocommerce_taxonomy_archive_description() function
 */
function woocommerce_taxonomy_archive_description()
{
    if (is_tax(array('product_cat', 'product_tag')) && get_query_var('paged') == 0) {
        global $wp_query;
        $term = $wp_query->get_queried_object();
        $thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
        $image = wp_get_attachment_url($thumbnail_id);
        $image_class = $image ? ' has-term-image' : null;
        $description = wc_format_content(term_description());
        if ($description) {
            echo '<div class="term-description' . $image_class . '">' . $description . '</div>';
        }
    }
}
 /**
  * @see Walker::start_lvl()
  *
  * @param string $output Passed by reference. Used to append additional content.
  * @param int $depth Depth of page. Used for padding.
  */
 public function start_lvl(&$output, $depth = 0, $args = array())
 {
     $indent = str_repeat("\t", $depth);
     $class = '';
     $after = '';
     if ($this->product_category) {
         if ($image_id = get_woocommerce_term_meta($this->product_category, 'thumbnail_id', true)) {
             $image_attributes = wp_get_attachment_image_src($image_id, 'thumbnail');
             $after = sprintf('<img src="%s" class="pull-right">', $image_attributes[0]);
             $class = 'has-image';
         }
     }
     $output .= "\n{$indent}<ul role=\"menu\" class=\" dropdown-menu {$class}\">\n{$after}";
 }
Exemplo n.º 16
0
function get_cats()
{
    $catTerms = get_terms('product_cat', array('hide_empty' => 0, 'include' => '1422, 1344, 984, 1446, 1000, 1050, 996, 975, 987, 1016, 994, 564, 1186, 1048, 654, 1135, 645, 1445'));
    $ch_n = 0;
    if ($catTerms) {
        echo '<ul class="ch-grid">';
        foreach ($catTerms as $catTerm) {
            $thumbnail_id = get_woocommerce_term_meta($catTerm->term_id, 'thumbnail_id', true);
            $image = wp_get_attachment_thumb_url($thumbnail_id);
            $ch_n++;
            echo '<li><a title="Перейти" href="/products/' . $catTerm->slug . '"><div class="ch-item" style="background-image: url(' . $image . '); background-size: 80%; background-repeat: no-repeat; background-color: white;"><div class="ch-info"><h3>' . $catTerm->name . '</h3></div></div></a></li>';
        }
        wp_reset_query();
        echo '</ul>';
    }
}
Exemplo n.º 17
0
function woocommerce_subcategory_thumbnail($category)
{
    $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
    if ($thumbnail_id) {
        $image = wp_get_attachment_image_src($thumbnail_id, 'full');
        $image = $image[0];
    } else {
        $image = wc_placeholder_img_src();
    }
    if ($image) {
        // Prevent esc_url from breaking spaces in urls for image embeds
        // Ref: http://core.trac.wordpress.org/ticket/23605
        $image = str_replace(' ', '%20', $image);
        echo '<img alt="' . esc_attr($category->name) . '" src="' . esc_url($image) . '" />';
    }
}
Exemplo n.º 18
0
function woocommerce_subcategory_thumbnail($category)
{
    // Figure
    $figure = \Drone\HTML::figure()->class('featured full-width');
    // Hyperlink
    $a = $figure->addNew('a')->attr(Everything::getImageAttrs('a', array('fancybox' => false)))->href(get_term_link($category->slug, 'product_cat'));
    // Thumbnail
    $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
    $thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_catalog');
    if ($thumbnail_id) {
        $a->add(wp_get_attachment_image($thumbnail_id, $thumbnail_size));
    } elseif (woocommerce_placeholder_img_src()) {
        $a->add(woocommerce_placeholder_img($thumbnail_size));
    }
    echo $figure->html();
}
Exemplo n.º 19
0
 function import_category_object($product_category)
 {
     try {
         $thumbnail_id = get_woocommerce_term_meta($product_category->cat_ID, "thumbnail_id", true);
         $image = wp_get_attachment_url($thumbnail_id);
         $this->set_value("id", $product_category->cat_ID);
         $this->set_value("slug", $product_category->slug);
         $this->set_value("description", $product_category->category_description);
         $this->set_value("feature", $image ? "<div class=\"img\" style=\"background: url('{$image}') no-repeat center center; background-size: cover; min-height: 150px;\"></div>" : "<div src=\"" . get_template_directory_uri() . "/library/img/default.jpg\" class=\"no-image\" ></div>");
         $this->set_value("ui_sref_id", "home.shop.products({CategoryID: '" . $product_category->cat_ID . "'})");
         //$this->products = new JSON_API_Products_Model($product_category->term_taxonomy_id);
         //print_r($product_category);
     } catch (WC_API_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array("status" => $e->getCode()));
     }
 }
Exemplo n.º 20
0
 public static function get_categories()
 {
     global $wp_query, $prdctfltr_global;
     $defaults = array('before' => '', 'after' => '', 'force_display' => false);
     $args = array();
     $args = wp_parse_args($args, $defaults);
     extract($args);
     $selected_term = isset($prdctfltr_global['active_taxonomies']['product_cat'][0]) ? $prdctfltr_global['active_taxonomies']['product_cat'][0] : '';
     if ($selected_term !== '') {
         if (term_exists($selected_term, 'product_cat')) {
             $term = get_term_by('slug', $selected_term, 'product_cat');
         }
     }
     if (!isset($term)) {
         $term = (object) array('term_id' => 0);
     }
     $parent_id = $term->term_id == 0 ? 0 : $term->term_id;
     $product_categories = get_categories(apply_filters('woocommerce_product_subcategories_args', array('parent' => $parent_id, 'menu_order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'taxonomy' => 'product_cat', 'pad_counts' => 1)));
     if ($product_categories) {
         echo $before;
         foreach ($product_categories as $category) {
             wc_get_template('content-product_cat.php', array('category' => $category));
         }
         if ($term->term_id !== 0) {
             $display_type = get_woocommerce_term_meta($term->term_id, 'display_type', true);
             switch ($display_type) {
                 case 'subcategories':
                     $wp_query->post_count = 0;
                     $wp_query->max_num_pages = 0;
                     break;
                 case '':
                     if (get_option('woocommerce_category_archive_display') == 'subcategories') {
                         $wp_query->post_count = 0;
                         $wp_query->max_num_pages = 0;
                     }
                     break;
             }
         }
         if ($term->term_id == 0 && get_option('woocommerce_shop_page_display') == 'subcategories') {
             $wp_query->post_count = 0;
             $wp_query->max_num_pages = 0;
         }
         echo $after;
         return true;
     }
 }
Exemplo n.º 21
0
function woocommerce_subcategory_thumbnail($category)
{
    $small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_catalog');
    $dimensions = wc_get_image_size($small_thumbnail_size);
    $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
    if ($thumbnail_id) {
        $image = wp_get_attachment_image_src($thumbnail_id, $small_thumbnail_size);
        $image = $image[0];
    } else {
        $image = wc_placeholder_img_src();
    }
    if ($image) {
        // Prevent esc_url from breaking spaces in urls for image embeds
        // Ref: http://core.trac.wordpress.org/ticket/23605
        $image = str_replace(' ', '%20', $image);
        echo '<img src="' . esc_url($image) . '" alt="' . esc_attr($category->name) . '"/>';
    }
}
 public function add_product_image_as_woocommerce_subcategory_thumbnail($category)
 {
     if ($this->let_category_image_override) {
         if (get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true)) {
             woocommerce_subcategory_thumbnail($category);
             return;
         }
     }
     $query_args = array('posts_per_page' => $this->randomize_category_image_from_products ? 10 : 1, 'post_status' => 'publish', 'post_type' => 'product', 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN')), 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category->term_id)));
     $products = get_posts($query_args);
     if ($products) {
         echo get_the_post_thumbnail($products[array_rand($products)]->ID, 'shop_thumbnail');
         echo get_the_post_thumbnail($products[array_rand($products)]->ID, 'shop_thumbnail');
         echo get_the_post_thumbnail($products[array_rand($products)]->ID, 'shop_thumbnail');
         echo get_the_post_thumbnail($products[array_rand($products)]->ID, 'shop_thumbnail');
         echo get_the_post_thumbnail($products[array_rand($products)]->ID, 'shop_thumbnail');
     }
 }
Exemplo n.º 23
0
function woocommerce_category_image()
{
    if (is_product_category()) {
        global $wp_query;
        $cat = $wp_query->get_queried_object();
        $thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true);
        $image = wp_get_attachment_url($thumbnail_id);
        global $virtue;
        if (isset($virtue['shop_layout']) && $virtue['shop_layout'] == "sidebar") {
            $cat_width = 770;
        } else {
            $cat_width = 1140;
        }
        $sizeimage = aq_resize($image, $cat_width, 300, true);
        if ($image) {
            echo '<div class="cat_main_img"><img src="' . $sizeimage . '" alt="" /></div>';
        }
    }
}
Exemplo n.º 24
0
 function et_brands($atts)
 {
     extract(shortcode_atts(array('title' => '', 'limit' => 10, 'display_type' => 'slider', 'columns' => 3, 'class' => ''), $atts));
     $output = '';
     $args = array('hide_empty' => false, 'number' => $limit);
     $terms = get_terms('brand', $args);
     $count = count($terms);
     $i = 0;
     if ($count > 0) {
         $output .= '<div class="et-brands-' . $display_type . ' ' . $class . ' columns-number-' . $columns . '">';
         if ($title != '') {
             $output .= '<h2 class="brands-title title"><span>' . $title . '</span></h2>';
         }
         $output .= '<ul class="et-brands">';
         foreach ($terms as $term) {
             $i++;
             $thumbnail_id = absint(get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true));
             $output .= '<li class="et-brand">';
             if ($thumbnail_id) {
                 $output .= '<a href="' . get_term_link($term) . '" title="' . sprintf(__('View all products from %s', ETHEME_DOMAIN), $term->name) . '"><img src="' . etheme_get_image($thumbnail_id) . '" title="' . $term->name . '"/></a>';
             } else {
                 $output .= '<h3><a href="' . get_term_link($term) . '" title="' . sprintf(__('View all products from %s', ETHEME_DOMAIN), $term->name) . '">' . $term->name . '</a></h3>';
             }
             $output .= '</li>';
         }
         $output .= '</ul>';
         $output .= '</div>';
         if ($display_type == 'slider') {
             $items = '[[0, 1], [479,2], [619,3], [768,3],  [1200, 4], [1600, 4]]';
             $output .= '<script type="text/javascript">';
             $output .= '     jQuery(".et-brands").owlCarousel({';
             $output .= '         items:1, ';
             $output .= '         navigation: true,';
             $output .= '         navigationText:false,';
             $output .= '         rewindNav: false,';
             $output .= '         itemsCustom: ' . $items . '';
             $output .= '    });';
             $output .= ' </script>';
         }
     }
     return $output;
 }
 /**
  * Prepare a single product attribute term output for response.
  *
  * @param WP_Term $item Term object.
  * @param WP_REST_Request $request
  * @return WP_REST_Response $response
  */
 public function prepare_item_for_response($item, $request)
 {
     // Get term order.
     $menu_order = get_woocommerce_term_meta($item->term_id, 'order_' . $this->taxonomy);
     $data = array('id' => (int) $item->term_id, 'name' => $item->name, 'slug' => $item->slug, 'description' => $item->description, 'menu_order' => (int) $menu_order, 'count' => (int) $item->count);
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($item, $request));
     /**
      * Filter a term item returned from the API.
      *
      * Allows modification of the term data right before it is returned.
      *
      * @param WP_REST_Response  $response  The response object.
      * @param object            $item      The original term object.
      * @param WP_REST_Request   $request   Request used to generate the response.
      */
     return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
 }
Exemplo n.º 26
0
    /**
     * Copy product Category Custom fields
     *
     * Copy the category custom fields from orginal category to its translations
     * when we start adding new category translation
     *
     * @return boolean false if this action must not be executed
     */
    public function copyProductCatCustomFields()
    {
        /* We sync custom fields only for translation */
        if (!(isset($_GET['from_tag']) && isset($_GET['new_lang']))) {
            return false;
        }
        $ID = esc_attr($_GET['from_tag']);
        $type = get_woocommerce_term_meta($ID, 'display_type', true);
        $thumbID = absint(get_woocommerce_term_meta($ID, 'thumbnail_id', true));
        $image = $thumbID ? wp_get_attachment_thumb_url($thumbID) : wc_placeholder_img_src();
        ?>
        <script type="text/javascript">
            jQuery('document').ready(function ($) {
                $('#display_type option[value="<?php 
        echo $type;
        ?>
"]')
                        .attr("selected", true);
                $('#product_cat_thumbnail img').attr('src', '<?php 
        echo $image;
        ?>
');
                $('#product_cat_thumbnail_id').val('<?php 
        echo $thumbID;
        ?>
');
        <?php 
        if ($thumbID) {
            ?>
                    $('.remove_image_button').show();
        <?php 
        }
        ?>
            });
        </script>
        <?php 
        /* Allow other plugins to check for category custom fields */
        do_action(HooksInterface::PRODUCT_COPY_CATEGORY_CUSTOM_FIELDS, $ID);
    }
 /**
  * Get category featured image
  *
  * @since 1.0.0
  * @param  string $size image size.
  * @return string
  */
 public function get_cat_image($size = 'full')
 {
     if (!function_exists('get_woocommerce_term_meta')) {
         return '';
     }
     $thumbnail_id = get_woocommerce_term_meta($this->object->term_id, 'thumbnail_id', true);
     $image = false;
     if ($thumbnail_id) {
         $image = wp_get_attachment_image_src($thumbnail_id, $size);
         $image = $image[0];
     } elseif (function_exists('wc_placeholder_img_src')) {
         $image = wc_placeholder_img_src();
     }
     if ($image) {
         // Prevent esc_url from breaking spaces in urls for image embeds
         // Ref: http://core.trac.wordpress.org/ticket/23605
         $image = str_replace(' ', '%20', $image);
         return sprintf('<img src="%1$s" alt="%2$s" />', esc_url($image), esc_attr($this->object->name));
     } else {
         return '';
     }
 }
    /**
     * Edit image size term meta for woocommerce category mosaic shortcode
     *
     * @access public
     * @return void
     */
    function wolf_category_metabox_edit($cat)
    {
        $sizes = array('1x1' => __('Square', 'wolf'), '2x1' => __('Landscape', 'wolf'), '1x2' => __('Portrait', 'wolf'), '2x2' => __('Big square', 'wolf'));
        ?>
		<tr class="form-field">
			<th scope="row" valign="top">
				<label for="thumbnail_size"><?php 
        _e('Image Size', 'wolf');
        ?>
</label>
			</th>
			<td>
				<select name="thumbnail_size" id="thumbnail_size">
					<?php 
        foreach ($sizes as $size => $size_name) {
            ?>
						<option value="<?php 
            echo esc_attr($size);
            ?>
" <?php 
            echo selected(get_woocommerce_term_meta($cat->term_id, 'thumbnail_size', true), $size);
            ?>
><?php 
            echo esc_attr($size_name);
            ?>
</option>
					<?php 
        }
        ?>
				</select>
				<p class="description"><?php 
        _e('Will be used for the mosaic categories shortcode only.', 'wolf');
        ?>
</p>
			</td>
		</tr>
	<?php 
    }
Exemplo n.º 29
0
function sf_product_cat_edit_hero_image($term)
{
    $image = '';
    $hero_id = absint(get_woocommerce_term_meta($term->term_id, 'hero_id', true));
    if ($hero_id) {
        $image = wp_get_attachment_url($hero_id, 'medium');
    } else {
        $image = wc_placeholder_img_src();
    }
    ?>
    	<tr class="form-field">
			<th scope="row" valign="top"><label><?php 
    _e('Hero Image', 'swiftframework');
    ?>
</label></th>
			<td>
				<div id="product_cat_hero" style="float:left;margin-right:10px;"><img style="height: auto!important;" src="<?php 
    echo esc_url($image);
    ?>
" width="300px" height="300px" /></div>
				<div style="line-height:40px;">
					<input type="hidden" id="product_cat_hero_id" name="product_cat_hero_id" value="<?php 
    echo $hero_id;
    ?>
" />
					<button type="submit" class="upload_hero_button button"><?php 
    _e('Upload/Add image', 'swiftframework');
    ?>
</button>
					<button type="submit" class="remove_hero_button button"><?php 
    _e('Remove image', 'swiftframework');
    ?>
</button>
					<p><?php 
    _e('This image is used for the hero image on product category pages.', 'swiftframework');
    ?>
</p>
				</div>
				<script type="text/javascript">

					// Uploading files
					var file_frame_hero;

					jQuery(document).on( 'click', '.upload_hero_button', function( event ){

						event.preventDefault();

						// If the media frame already exists, reopen it.
						if ( file_frame_hero ) {
							file_frame_hero.open();
							return;
						}

						// Create the media frame.
						file_frame_hero = wp.media.frames.downloadable_file = wp.media({
							title: '<?php 
    _e('Choose an image', 'swiftframework');
    ?>
',
							button: {
								text: '<?php 
    _e('Use image', 'swiftframework');
    ?>
',
							},
							multiple: false
						});

						// When an image is selected, run a callback.
						file_frame_hero.on( 'select', function() {
							attachment = file_frame_hero.state().get('selection').first().toJSON();

							jQuery('#product_cat_hero_id').val( attachment.id );
							jQuery('#product_cat_hero img').attr('src', attachment.url );
							jQuery('.remove_hero_button').show();
						});

						// Finally, open the modal.
						file_frame_hero.open();
					});

					jQuery(document).on( 'click', '.remove_hero_button', function( event ){
						jQuery('#product_cat_hero img').attr('src', '<?php 
    echo wc_placeholder_img_src();
    ?>
');
						jQuery('#product_cat_hero_id').val('');
						jQuery('.remove_hero_button').hide();
						return false;
					});

				</script>
				<div class="clear"></div>
			</td>
		</tr>
    <?php 
}
Exemplo n.º 30
0
function woo_ce_get_category_thumbnail_url($category_id = 0, $size = 'full')
{
    if ($thumbnail_id = get_woocommerce_term_meta($category_id, 'thumbnail_id', true)) {
        $image_attributes = wp_get_attachment_image_src($thumbnail_id, $size);
        if (is_array($image_attributes)) {
            return current($image_attributes);
        }
    }
}