Reputation: 987
I want to show the value set in a custom field to show up in the shop loop item. It is working for the shop and its showing the product based custom field. But the items on the product page itself show all the value of the product-page instead of the individual product. How do I have to modify the code so its working?
add_action('woocommerce_after_shop_loop_item', 'grundpreis');
function grundpreis () {
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'grund-preis', true);
wp_reset_query();
}
Its working here: https://keimster.de/shop/ but not here: https://keimster.de/produkt/vier-koerner-keimster
Upvotes: 0
Views: 343
Reputation: 29614
Can you try the following code? I believe the problem is with $wp_query
function grundpreis () {
global $post;
// Check for the custom field value
$my_field = get_post_meta($post->ID, 'grund-preis', true);
if ( $my_field ) {
echo $my_field;
}
}
add_action('woocommerce_after_shop_loop_item', 'grundpreis', 10, 0 );
Upvotes: 1