Php 如何获取商业订单项目中的ACF产品字段值
我正在修改我的店铺,以便在下订单后在WooCommerce订单页面上显示自定义字段 我的代码被插入到默认的Php 如何获取商业订单项目中的ACF产品字段值,php,wordpress,woocommerce,advanced-custom-fields,orders,Php,Wordpress,Woocommerce,Advanced Custom Fields,Orders,我正在修改我的店铺,以便在下订单后在WooCommerce订单页面上显示自定义字段 我的代码被插入到默认的/themes/mytheme/woocommerce/order/order details item.php中。这是读取字段的部分: $per_unit_or_square = get_field('pricem2_or_priceunit_', $product->get_id()); if (!empty($per_unit_or_square)) { if ($pe
/themes/mytheme/woocommerce/order/order details item.php
中。这是读取字段的部分:
$per_unit_or_square = get_field('pricem2_or_priceunit_', $product->get_id());
if (!empty($per_unit_or_square)) {
if ($per_unit_or_square == 'unit') {
$pricingtype_order_received = '<span class="pricingtype_order_received">'.__(' unit ', 'mbb').'</span>';
} elseif ($per_unit_or_square == 'm2') {
$pricingtype_order_received = '<span class="pricingtype_order_received">'.__(' m<sup>2</sup> ', 'mbb').'</span>';
} else {
$pricingtype_order_received = '<span class="pricingtype_order_received">'.__(' pcs ', 'mbb').'</span>';
}
}
我的问题是代码不起作用,并且没有检索到收到的$pricingtype\u order\u
值。同样的逻辑也适用于购物车和其他页面,但不适用于订单,也不适用于订单发出后的电子邮件
去哪里找?是否可以通过订单和电子邮件读取ACF字段
如果有人感兴趣,下面是完整的代码:尝试用
$item->get\u product\u id()
替换$product->get\u id()
,例如:
$per_unit_or_square = get_field( 'pricem2_or_priceunit_', $item->get_product_id() );
相关:当然可以,只需等待stackoverflows允许我接受即可
$per_unit_or_square = get_field( 'pricem2_or_priceunit_', $item->get_product_id() );