首页 文章

Woocommerce在购物车和结帐中获取自定义字段值

提问于
浏览
1

我想让 custom field value of a WooCommerce product 显示商店系统的 on different pages . 我成功地为单个产品页面执行了此操作,但相同的代码不适用于购物车 .

对于单个产品,我在functions.php中使用了这个代码,工作正常:

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

我为购物车尝试了相同的代码,但这次这些值没有显示在页面上 . 我也提到了这个帖子(Woocommerce getting custom attributes),将$ post更改为$ product,但仍然没有输出...

有什么建议?

1 回答

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

    你可以试试这个,这对我很有用 .

相关问题