Skip Navigation

[Resolved] WooCommerce category image size's isn't working

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 9 replies, has 2 voices.

Last updated by thomasS-11 5 years, 9 months ago.

Assigned support staff: Waqas.

Author
Posts
#264142

This post is a comment for:
https://toolset.com/forums/topic/show-a-list-of-woocommerce-categories-with-images/
- Please consider possibility to reopen or comment on closed topics as this would be more fit for a comment on above link!

i can't get size to work with this solution? - other than that it works fine.. but i tried defining size="thumbnail/medium/large/brands-thumb (this is custom)" but none of them work!

Notice that i tried above size values separately, i did not use them as written above.

Also, why isnt the category images included native with WP-Views/WooCommerce Views?

This is a duplicate of: https://toolset.com/forums/topic/woocommerce-category-image-sizes-not-working/ - i just assigned it by accident! i dont want it to be assigned, as it slows down the processing time. Please delete my other post similar to this.

#264168

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Can you please try add_image_size() Word Press API function in your theme's functions.php, to register your desired size, and then use it in your custom logic (where you retrieve the thumbnail)? Sometimes themes may have not register the sizes and WP works on default settings.

You can find information on add_image_size() at http://codex.wordpress.org/Function_Reference/add_image_size

#264423

I did add image size in functions.php .. thats what im saying.. but views does not detect the image size .. even without adding image size it should still be able to pull the default "thumb" "medium" and "large" image sizes as they are standard in WordPress.. Please look at the provided link to understand what i am talking about.. I added some code to make the images work for product categories.. i think there must be done something to make the image sizes available as well.. its not just simply adding new image size in functions.php.

#264426

This is the code i added in my Functions.php file. notice the bottom line, it has a add image size call.. but like i said in prev. comment, it shouldnt be needed as there is also the default image sizes that does not work. But to help you understand better, i paste my code here.
The code is used to make category images available in Views.
Further more, the Taxonomy images should be included in the WP-Views / Woocommerce Views as standard! i didnt expect to use time writing code to make a category image available in views. Afterall you stated that WP-Views is "CODE FREE"..

Here is the code:

/*SHORTCODE FOR WP-VIEWS CATEGORY IMAGE*/
add_shortcode('views_output_woocommerce_category_image','views_output_woocommerce_category_image_func');
function views_output_woocommerce_category_image_func() {   
    global $WP_Views;
    //Get Taxonomy info
    $taxonomydata_passed_by_views=$WP_Views->taxonomy_data;
     
    //Get Term info
    $term_info_tax=$taxonomydata_passed_by_views['term'];
     
    //Get Term ID
    $term_id_tax=$term_info_tax->term_id;
     
    //Get Thumbnail ID assigned to that term ID
    $thumbnail_id = get_woocommerce_term_meta( $term_id_tax, 'thumbnail_id', true );
     
    //Get the Image URL for that thumbnail ID
    $image = wp_get_attachment_url( $thumbnail_id );
     
    //If image exist, return it to the shortcode
    if ( $image ) {
        return '<img src="' . $image . '" alt="" />';
    }
     
}


add_image_size( 'brands-thumb', 320, 169, true );
#264517

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Can you please try using wp_get_attachment_image_src() function in place of wp_get_attachment_url() function? Since 'wp_get_attachment_image_src' is capable of returning the desired size. Please have a look at http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src for more information. Hope this can sort out this issue.

Categories/Taxonomies are standard features of Word Press, which still don't have such additional information by default. Since this isn't a must-have requirement around Word Press community, that's why it is dealt as an added option. You can use 3rd party plugins to add category images, rather than writing a custom code, like:

- https://wordpress.org/plugins/categories-images/
- https://wordpress.org/plugins/featured-images-for-categories/

Please let me know if I can help you with anything related.

#264536

Hi again.

Replacing wp_get_attachment_image_src() instead of wp_get_attachment_url() doesnt work..

Well actually, categories / taxonomy images IS a standard for WooCommerce, therefore i think its kind of missing if you consider the plugin name is WooCommerce Views. As the name WooCommerce is included, i would expect that it integrates with WooCommerce's default settings like Category image.

The main reason i dont want to use plugins for this, is that WooCommerce already has category images, and it would be stupid to add a plugin for category images - i will then end up having 2 category images and that to me, seems really stupid and confusing - and seems like a "let's just get this over with"-solution..

Further more i always create websites with as LESS PLUGINS AS POSSIBLE due to speed and update troubles - i dont want to use a plugin for such a feature as it is really unnecessary and can be done without. Thats the 2 main reasons i dont want to use the plugins.. and one of the provided plugins in your comment doesnt even have 1 5-star rating, so i dont even want to try that plugin..

I could understand this solution if it was a custom plugin or something that has nothing to do with what you provide.. but as mentioned above, WP-Woocommerce views claims to be able to do WooCommerce codefree.

How would you modify the provided code above to make it work?
If you can't - could you please then ask someone from your team how to?

And please consider adding this to WooCommerce views at least, as it is a standard feature that comes with WooCommerce.

Thank you.

#264981

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I have discussed with the relevant Dev Team, and they have recently worked around this feature. Please allow me a day to return to you with some solution.

Your patience and cooperation is much appreciated, thank you.

#265312

Thank you.

#265853

Waqas
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I have just received following detailed updates by Dev Team. I am copying as-it-is so you can have full information.

-- Starts --
Attached is the WooCommerce Views 2.4 development version (sent you in an email to your email address) for testing with our client relating to WooCommerce category images. Take note that this is final development (after all my own tests). But this has not been passed to QA yet. So I suggest our client should be testing this on his own dev site , not on production sites.

Below is how to output WooCommerce product category image using this version:

This is the shortcode in general. This can be inserted in the Views shortcode inserter under "WooCommerce" groups "WooCommerce Product category image" (see attached screenshot 1).

[wpv-woo-productcategory-images]

Outputs WooCommerce product category image set in the backend. (Products -> Categories). Tested to work loops outputting categories.

Parameters:

[wpv-woo-productcategory-images size="shop_single" output="raw"]

size: The size of the image. WooCommerce Views will automatically determine supported sizes based on your existing media setttings. You can also add custom sizes through http://codex.wordpress.org/Function_Reference/add_image_size and add that to your active theme functions.php

Then this will appear as one of the sizing options.
Default: “shop_single?? -standard WooCommerce product image size option.

output: The format. Possible values:
-> “raw?? = outputs raw URL to the category image.
-> “img_tag?? = outputs HTML img_tag.
Default: “raw??

Example usage: (outputs img tag of the category image in thumbnail size)

[wpv-woo-productcategory-images output="img_tag" size="thumbnail"]

When there is no image set, it will output empty or no image markup.

Take note that our client does not anymore need those custom PHP functions in functions.php. I suggest it to be removed and have the entire implementation using the new WooCommerce Views category image shortcode.

For best compatibility, client should be using latest Types and Views as available on our wp-types.com downloads page. And also using latest WooCommerce version (which is version 2.2.8 as of this time.)

Once again, if our client wants "custom" sizes (not the standard sizes from WooCommerce or media library). Then this is also supported. All he needs to do is to add a custom size function using add_image_size: http://codex.wordpress.org/Function_Reference/add_image_size

He needs to add that one to functions.php. Then once this is added properly, it will now appear as one of the sizing options when inserting category images through the shortcode in Views.
-- Ends --

Please consider following carefully as mentioned above, and let me know if it resolves the problem.

Thank you for your patience and cooperation.

#271449

Best ever answer! 🙂