在单个产品页面中添加自定义文本字段

我正在woocommerce中的一个项目。

有人可以帮我在”添加到购物车”旁边添加自定义文本字段吗?

我尝试了以下操作, 但无法正常工作。

add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );

function add_custom_field() {
    global $post;

    echo "<div class='prod-code'>Product Code: ";
    $text= get_field('txt-field', $post);
    echo "</div>";

    return true;
}

#1


也许尝试像这样使用$ post-> ID:

add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );

function add_custom_field() {
    global $post;

    echo "<div class='prod-code'>Product Code: ";
    $text= get_field('txt-field', $post->ID);
    echo "</div>";

    return true;
}

#2


将你的html代码放入content-product.php(wp-content / themes /你的主题/woocommerce/content-product.php)content-product.php包含wordpress中列表页面的代码。如果要编辑产品页面, 则要编辑content-single-product.php。

来源:

https://www.srcmini02.com/67134.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?