1

I am trying to get the custom field value of a WooCommerce product to display on different pages of the shop system. I succeeded to do so for the single product page, but the same code doesn't work for the cart.

For the single product I used this code within the functions.php, which works fine:

global $post;
echo '<p>' . get_post_meta($post->ID, 'my-custom-field', true) . '</p>';

I tried the same code for the cart, but this time the values don't show on the page. I also referred to this thread (Woocommerce getting custom attributes), changing $post to $product, but still no output...

Any suggestions?

Community
  • 1
  • 1
bjh81
  • 11
  • 3

1 Answers1

0
<?php
echo get_post_meta( get_the_ID(), 'slug/id', true );
?>

You Can try this, This works for me Very well.

Morshed Maruf
  • 80
  • 1
  • 8