如何在Woocommerce产品页面显示自定义字段?

时间:2020-03-12 14:37:22

标签: php wordpress

我正在尝试在woocoomerce产品页面中显示名为 youtube_url 的自定义字段(包含YouTube视频的URL)。我创建了一个名为/ products /的页面,并使用 [products] 短代码来显示所有产品。在标题下,我想显示自定义字段。通过添加以下内容,我可以在单个产品页面上显示 youtube_url 自定义字段:

$post_meta_value = get_post_meta($post->ID, 'youtube_url', true ); 

到产品模板,但我无法显示显示所有产品的[products]简码。我在wc-template-fuction.php文件中添加了相同的代码:

if ( ! function_exists( 'woocommerce_template_loop_product_title' ) ) {

    /**
     * Show the product title in the product loop. By default this is an H2.
     */
    function woocommerce_template_loop_product_title() {
        echo '<h2 class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . '</h2>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        // Custom Fields 
        $post_meta_value = get_post_meta($post->ID, 'DREAM_auto_price', true ); 
        echo $post_meta_value;
        //
    }
}

但无法使其正常工作。有什么建议吗? :-)

谢谢

0 个答案:

没有答案