I have this function to echo the 'my_custom_field' value, and it works fine:

add_action('woocommerce_before_add_to_cart_form' , 'my_function');

function my_function(){

    echo get_post_meta( get_the_ID(), 'my_custom_field', true ); 


But this only prints the value. I need to also print the translated title of this custom field. How can get this?

  • Which plugin you use for translate title ?
    – Nefro
    Commented Nov 18, 2016 at 13:58
  • @Nefro I use WPML
    – JPashs
    Commented Nov 18, 2016 at 14:35
  • did you try "echo get_post_meta( get_the_title(), 'my_custom_field', true ); "?
    – rudtek
    Commented Nov 18, 2016 at 17:11
  • @rudtek I tried it, but print nothing.
    – JPashs
    Commented Nov 23, 2016 at 9:35

1 Answer 1


can you do this:

get_post_meta(get_the_ID(), '', true);


get_post_meta(get_the_ID(), 'my_custom_field');

the first will pull all custom post type on the current post, and the second restricts to the field. You should get an array and then you'll know which item in your array is the field title you're looking to pull. then you can use that to return title

  • I get the id but now how do I print the title?
    – JPashs
    Commented Nov 24, 2016 at 12:04
  • can you tell me what is returned when you print the meta array? That will help me know your meta structure and then we can get it to print what you need
    – rudtek
    Commented Nov 28, 2016 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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