I m working on content-product of woocommerce and doing shortcode in the template as echo do_shortcode ('[product_attribute attribute="Grams"]'); where Grams are in my backend as attribute and it hasvalues, but nothing get printed out.Is it a wrong query or i need to do something else?

  • Did you add the shortcode using add_shortcode()? – mantis Nov 21 '13 at 10:46
  • no, i just did do_shortcode(), where should i be adding add_shortcode – Nofel Nov 21 '13 at 10:47
  • 1
    If the [product_attribute] shortcode does not exist then you must create it. Take a look at how to use/create shortcodes. – helgatheviking Nov 21 '13 at 10:49
  • 1
    I don't know much about woocommerce specifically but you need to make sure that the shortcode is added to begin with. Can you look in the plugin and find where it is added? See the link in the comment above. – mantis Nov 21 '13 at 10:50
  • 1
    Apparently product_attribute is a shortcode for WooCommerce. Where are you placing it in your template? I would assume it needs to be in the loop to grab the correct product ID. – helgatheviking Nov 21 '13 at 11:02

I may have found the problem (from product_attribute)

 'per_page' => '12',
 'columns' => '4',
 'orderby' => 'title',
 'order' => 'asc',
 'attribute' => 'asc',
 'filter' => 'asc'

[product_attribute attribute='color' filter='black']

Notice the attibute is in single quotes wheras yours is in double quotes:

do_shortcode ('[product_attribute attribute="Grams"]');

also you may need it to be in lowercase letters.

From The codex:

IMPORTANT TIP - Don't use camelCase or UPPER-CASE for your $atts attribute names $atts values are lower-cased during shortcode_atts( array( 'attr_1' => 'attr_1 default', // ...etc ), $atts ) processing, so you might want to just use lower-case.

| improve this answer | |
  • i tied that before posting here, but it didn't work. how can i find where is woocommerce_single_product_summary, maybe i can extract things that i want from it? – Nofel Nov 21 '13 at 12:01
  • So you changed it to do_shortcode ('[product_attribute attribute='grams']');? because it specifically says not to use capital letters as attributes and you do need single quotes. – mantis Nov 21 '13 at 14:19
  • the code gives a highlight, i used double quotes as its quotes inside quotes. – Nofel Nov 21 '13 at 14:27
  • Try inversing them using the double quotes on the outside. Also did you change grams to lowercase? – mantis Nov 21 '13 at 14:36
  • Also did you try something instead of attribute? Like order='asc' – mantis Nov 21 '13 at 14:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.