在具有高级自定义字段插件的Woocommerce中,我们为 products 添加了一个自定义字段,并且每个 product 的字段值为 specific .
现在我正在尝试将此自定义字段值添加到我们的Woocommerce订单确认电子邮件中 .
我尝试了以下代码但没有成功:
<?php
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$order_id = int_val( $order->id ); // Older than 3.0
} else {
$order_id = int_val( $order->get_id() ); // 3.0+
}
$inst1 = get_field(‘how1’, $order_id );
if( $inst1 ){
echo '<p>' . $inst1 . '</p>';
}
?> with Advanced Custom Fields plugin
1 回答
作为您的自定义字段 is specific to "product" post type (但不是"order"帖子类型)您需要 to get first the order items 来获取 the product ID ,您应该以这种方式使用ACF
get_field()
函数:将为订单中的每个项目显示自定义字段值,因为订单中可包含许多项目 .
参考文献:
How to get WooCommerce order details
Get Order items and WC_Order_Item_Product in Woocommerce 3