我在 WooCommerce 产品上为帖子类型设置了高级自定义字段。因此每个产品都有 1 个独特的自定义字段。
我试图在购物车上的产品名称以及结账页面和订单表信息之后显示自定义字段。
但是,由于我的代码不显示任何输出,因此遇到了问题。
任何有关如何实现这一目标的建议将不胜感激。谢谢
// Display the ACF custom field 'location' after the product title on cart / checkout page.
function cart_item_custom_feild( $cart_item ) {
$address = get_field( 'location', $cart_item['product_id'] );
echo "<div>Address: $address.</div>";
}
add_action( 'woocommerce_after_cart_item_name', 'cart_item_custom_feild', 10, 1 );
Run Code Online (Sandbox Code Playgroud)
我也尝试过the_field而不是get_field
php wordpress woocommerce advanced-custom-fields woocommerce-theming