1

I've set up some custom fields using the existing 'custom fields' panel on a WooCommerce product page. I'm unable to display these on the front end. My technical knowledge is limited but I've tried every example and code snippet found elsewhere on this site, including;

// Display Custom Field Value
echo get_post_meta( $post->ID, 'field', true );

and a bunch of others.

However, when I use the_meta(), which, from what I understand, should display all meta, it gives me this on the front end:

frs_woo_product_tabs: a:1:{i:0;a:3:{s:5:"title";s:12:"License Info";s:2:"id";s:16:"tab-license-info";s:7:"content";s:19:"License description";}}

It doesn't appear to recognize any of the custom fields that I've entered. Am I missing something obvious?

2

Where are you pasting that code?

The code snippet needs to be put in the right spot. So you need to copy the content-product.php template from the woocommerce plugin folder and place it in your theme folder in a "woocommerce" folder. Then paste that code within the Loop.


Updated Answer:

Okay so I believe that you need to use the get_post_custom function.

Take note of the Name of your custom field. Then we can something like this to output the results:

<?php

  $custom_fields = get_post_custom($post->ID);
  $my_custom_field = $custom_fields["Name of your Field"];
  foreach ( $my_custom_field as $key => $value ) {
      echo "<strong>$key: </strong> $value <br />";
  }

?>
  • I used a csv file to populate the custom fields and they saved fine, but when I use echo get_post_meta( $post->ID, 'my_field', true ); it won't display anything. If I manually add and save the custom field on the product page it displays the fields. Also, if I use <?php the_meta(); ?> it displays all of the csv imported fields. I really need to use the CSV option because of the quantity involved as well as selecting which fields to display. Not really sure how to proceed – kamala Feb 27 '15 at 2:27
  • Where are you using echo get_post_meta( $post->ID, 'my_field', true ); ?! – ngearing Feb 27 '15 at 2:50
  • Hi Nath, I'm placing it in the description.php found in woocommerce\single-product\tabs – kamala Feb 27 '15 at 2:56
  • Okay good. Try <?php $custom = get_post_custom($post_id); var_dump($custom); ?> And let us know if that spits anything out. – ngearing Feb 27 '15 at 3:04
  • It sure did, but not what I was expecting! It's rather long and has been cut short by the character limit here; array(46) { ["_sku"]=> array(1) { [0]=> string(6) "sku-21" } ["_downloadable"]=> array(1) { [0]=> string(2) "no" } ["_virtual"]=> array(1) { [0]=> string(2) "no" } ["_price"]=> array(1) { [0]=> string(2) "20" } ["_visibility"]=> array(1) { [0]=> string(7) "visible" } ["_stock"]=> array(1) { [0]=> string(0) "" } ["_stock_status"]=> array(1) { [0]=> string(7) "instock" } ["_backorders"]=> array(1) { [0]=> string(2) "no" – kamala Feb 27 '15 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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