如何向WooCommerce的相关产品部分中的每个产品添加自定义字段输出


How to add a custom field output to to each product in the related products section in WooCommerce?

因此使用related.php在主题目录中的单一产品目录中,以避免覆盖更新,我试图找到一种方法来显示每个相关产品的自定义字段。

<div class="related products">
    <h2><?php _e( 'You might also like...', 'woocommerce' ); ?></h2>
    <?php woocommerce_product_loop_start(); ?>
        <?php while ( $products->have_posts() ) : $products->the_post(); ?>
            <?php wc_get_template_part( 'content', 'product' ); ?>
        <?php endwhile; // end of the loop. ?>
    <?php woocommerce_product_loop_end(); ?>
</div>

我猜,并尝试了各种方法来避免使用默认模板在这里。

<?php while ( $products->have_posts() ) : $products->the_post(); ?>
            <?php wc_get_template_part( 'content', 'product' ); ?>
        <?php endwhile; // end of the loop. ?>
通过

  <?php while ( $products->have_posts() ) : $products->the_post(); ?>
            <div> 
                            <?php the_title(); ?> 
                            /// output image
                            /// out put custom field from each product
                            </div>

        <?php endwhile; // end of the loop. ?>

if ( $products->have_posts() ) : ?>
    <div class="related products">
        <h2><?php _e( 'You might also like...', 'woocommerce' ); ?></h2>
<div id="grid-wrapper">
<div id="the-grid">
        <?php woocommerce_product_loop_start(); ?>
            <?php while ( $products->have_posts() ) : $products->the_post(); ?>
                <?php //wc_get_template_part( 'content', 'product' ); ?>
<div class="grid-rect iso isotope-item">
<a href="<?php echo get_permalink(); ?>"> <!-- get product url -->
<?php if ( has_post_thumbnail() ) {the_post_thumbnail();}?> <!-- get product image -->
<h3><?php echo the_title() . " by, " . get_post_meta( get_the_ID(), 'wpcf-bb_author', true ); ?></h3> <!-- get tiel and author from custom field -->
</a>
</div>
            <?php endwhile; // end of the loop. ?>
        <?php woocommerce_product_loop_end(); ?>
</div> <!-- end of the-grid -->
</div> <!-- end of grid wrapper -->
    </div> <!-- end of related -->
<?php endif;