Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display WooCommerce product attribute archive links on product page, right below the add to cart button.
@Jibbon
Copy link

Jibbon commented May 18, 2012

Hi Coen, I can't get this code to work: "Catchable fatal error: Object of class WP_Error could not be converted to string in...." Any ideas?

@coenjacobs
Copy link
Author

coenjacobs commented May 18, 2012

Have you inserted your attribute name in the variable on line 15?

@Jibbon
Copy link

Jibbon commented May 18, 2012

Thanks for the reply. Yep, sure have...

@coenjacobs
Copy link
Author

coenjacobs commented May 20, 2012

I think the error is caused by products not containing any categories. Added a check for an empty array in the latest revision.

@Jibbon
Copy link

Jibbon commented May 20, 2012

Still no luck I'm afraid. Same error.

@coenjacobs
Copy link
Author

coenjacobs commented May 21, 2012

Updated again, can you try again?

@Jibbon
Copy link

Jibbon commented May 21, 2012

Thanks again Coen, but same error: "Catchable fatal error: Object of class WP_Error could not be converted to string in..."
Could you explain what this predefined $brand is and how Woo uses it? I'll try and help trouble shoot if I can...

@coenjacobs
Copy link
Author

coenjacobs commented May 21, 2012

And you are absolutely sure that the name you enter in line 15 is the exact name of the attribute? You could for example use 'product_cat' to show the product categories linked to it.

$brand is not a predefined variable, it is used from another example. I've updated it to a standardized version, using local $terms and $term variables.

@Jibbon
Copy link

Jibbon commented May 22, 2012

My apologies Coen, my stupidity: I wasn't giving the "pa_" prefix to the attribute name!!!! Sorry, and thanks!

@richangel
Copy link

richangel commented Jul 13, 2012

Hi Coen,

I'd have a question regarding this: With slight code changes, would it also be possible showing the attribute values (e.g. for attribute pa_brand - value "Calvin Klein") beneath the product images in the product categories? Basically what I would like to do is add additional information next to my product images, so users can already see certain specifications of my items, before having to go to the single product page.

Thanks a lot,
Rich

@coenjacobs
Copy link
Author

coenjacobs commented Jul 19, 2012

@richangel Yes, you would basically be using another hook, like 'woocommerce_after_shop_loop_item_title' or 'woocommerce_after_shop_loop_item' for example. The rest of the code doesn't really change much.

@richangel
Copy link

richangel commented Jul 23, 2012

Great, thanks a lot for your answer, I will give it a shot!

Rich

@perezfigueroa
Copy link

perezfigueroa commented Aug 13, 2012

Thanks @coenjacobs

I added the code but it only shows one (the first one) $term->name

For some reason the loop is not working. Do you have any suggestion? Thanks!

@perezfigueroa
Copy link

perezfigueroa commented Aug 13, 2012

I'm trying to show all terms for an attribute in a list in sidebar, so I think the problem is that $post->ID is for a specific Post. I need to call the entire list (values for the specific attribute)... Any suggestions? Thnaks!

@mchrislay
Copy link

mchrislay commented Jan 9, 2013

I created a Folder, and placed the php in a .txt file from above, change line 15 to "pa_brand" "pa_popular-designs"

I don't get an error, but nothing happens, no attributes showing.

Does this code still work with latest woo & wp? would love to use it

@ujesse
Copy link

ujesse commented Mar 8, 2013

Hi Coen
I'm trying to make this into a shortcode, so that if I put it on a page a list of the specified product attributes will show up as links. Is that possible?>
Thanks

@PuffDragon
Copy link

PuffDragon commented Nov 8, 2013

Hi Coen
I have the same problem - no error but nothing showing.
Is there something I need to change for more recent versions of woocommerce and WP?
Thanks!

@coenjacobs
Copy link
Author

coenjacobs commented Nov 11, 2013

Nope, this code works fine in the latest versions of WooCommerce and WordPress.

Make sure you get the attribute slugs exactly right (including the pa_ prefix) and it will work, just tested it.

@maturinpt
Copy link

maturinpt commented Nov 30, 2013

Hi,

I confirm, the code works with pa in the prefix of the attributes.
But
How to display on one single line one attribute and then a second line a second attribute
(with the automatic loop)

@speedwheel
Copy link

speedwheel commented Dec 18, 2013

Hello, this works just fine, but after I click the attribute it shows a white page. I did this stuff here http://wcdocs.woothemes.com/codex/extending/using-custom-attributes-in-menus/ but still not working.

@Valdimarsson
Copy link

Valdimarsson commented Jan 30, 2014

Hi, this is a nifty little "plugin" and it's working flawlessly.

I'm trying to remove the attribute name from the add_action but I've tried everything and it gives me all kinds of different errors. Are there a easy way to change this. Ex.: Buttonsize 3/4 should become Button is 3/4. I would still like the slug to be buttonsize.

Thanks in advance and if this isn't possible it's still a rather nice piece of code :-D

Best regards
Valdimarsson

@mew4mikkel
Copy link

mew4mikkel commented Feb 28, 2014

Well, having not to much PHP-experiance, I would like to know where to put this plugin? Functions.php? A .php-file for by itself? Or where?

I am trying to put an attribute with the property fx: Condition: Used, right next to the SKU in the product_meta div..

Help would be greatfully appreciated!

@jhinden
Copy link

jhinden commented Jun 28, 2014

I can't get this to work. If my attribute name is 'format', I put pa_format (format being the name of the attribute) and they don't show up. Should it be '<pa_format>' or 'pa_format' or pa_format? Neither seem to work. Thanks!

@dfmpmag
Copy link

dfmpmag commented Apr 12, 2017

Hello,
From last update of Woocommerce I have label "Product" in front of every attribute name. Please how could I remove it?
Thanks

@seldimi
Copy link

seldimi commented Aug 23, 2017

Change hook
add_action( 'woocommerce_shop_loop_item_title', 'cj_show_attribute_links' );

@MVMORADIA
Copy link

MVMORADIA commented Mar 25, 2019

I want to add Link in attributes Value and want to display Link in attributes Value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment