Skip to content
Advertisement

Replace WooCommerce attribute labels by a custom image for each

I am working on project and I need some group help.

I am using woocommerce product system and on shop archive page product I am showing attribute-label: attribute-value (just like text).

attribute-label:attribute-value (ex. Transmission: Manual)

Is there a way to show attribute-label as image? I can’t add html code like <img src..."/> and styling with CSS doesn’t help too.

I have searched for plugins and more.. But nothing on web.

To show attributes on product shop page i have used this function:

JavaScript

Can someone help me with this? How to change attribute-label with image?

Advertisement

Answer

Updated since WC 3.2+

As Product attributes dont have images, you should create a in your active theme a folder images (if it doesn’t exist) and inside a subfolder attributes.

For each product attribute, you will have to add an image inside this subfolder attributes, which name will be the name of your attribute (the slug). For example for “Color” attribute you will have to add an image named color.jpg.

Then I have make some changes in your code, to get this working. Only the terms set in the product for each attribute will be displayed. For each attribute you will get an image.

Here is the code:

JavaScript

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and work.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement