Php 在商业订单管理页面(ACF)中输出产品自定义字段

Php 在商业订单管理页面(ACF)中输出产品自定义字段,php,wordpress,woocommerce,advanced-custom-fields,orders,Php,Wordpress,Woocommerce,Advanced Custom Fields,Orders,在WooCommerce中,我使用来跟踪我实际存储每个产品的位置 当收到订单时,我希望能够查看管理员编辑订单页面,并查看项目的存储位置。所以我可以把它拿到船上 下面是我想看到的图片: 希望这是有道理的 我只想在Wordpress的编辑订单管理页面上调用每个产品的单个产品ACF变量(BinLocation)。有什么帮助吗 谢谢。更新:使用woocommerce\u-before\u-order\u-itemmeta操作挂钩中的自定义功能,您将能够实现您想要的: add_action( 'wooc

在WooCommerce中,我使用来跟踪我实际存储每个产品的位置

当收到订单时,我希望能够查看管理员编辑订单页面,并查看项目的存储位置。所以我可以把它拿到船上

下面是我想看到的图片:

希望这是有道理的

我只想在Wordpress的编辑订单管理页面上调用每个产品的单个产品ACF变量(BinLocation)。有什么帮助吗


谢谢。

更新:使用
woocommerce\u-before\u-order\u-itemmeta
操作挂钩中的自定义功能,您将能够实现您想要的:

add_action( 'woocommerce_before_order_itemmeta', 'storage_location_of_order_items', 10, 3 );
function storage_location_of_order_items( $item_id, $item, $product ){
    // Only on backend order edit pages
    if( ! ( is_admin() && $item->is_type('line_item') ) ) return;

    // Get your ACF product value (replace the slug by yours below)
    if( $acf_value = get_field( 'BinLocation', $product->get_id() ) ) {
        $acf_label = __('Stored in: ');

        // Outputing the value of the "location storage" for this product item
        echo '<div class="wc-order-item-custom"><strong>' . $acf_value .  $acf_label . '</strong></div>';
    }
}
add_action('woocommerce_-before_-order_-itemmeta','storage_-location_-of_-order_-items',10,3);
功能存储\u订单\u项的位置\u($item\u id,$item,$product){
//仅在后端订单编辑页面上
if(!(is_admin()&&&$item->is_type('line_item'))返回;
//获得你的ACF产品价值(用你的替换下面的slug)
如果($acf\u value=get\u字段('BinLocation',$product->get\u id()){
$acf_标签=_('存储在:');
//输出此产品项的“位置存储”值
回显“”。$acf\U值。$acf\U标签。“”;
}
}
代码可以放在活动子主题(或主题)的任何php文件中,也可以放在任何插件php文件中

这段代码经过测试,可以在WooCommerce版本3及更高版本中使用



更新:使用
woocommerce\u-before\u-order\u-itemmeta
操作挂钩中的自定义功能,您将能够实现您想要的:

add_action( 'woocommerce_before_order_itemmeta', 'storage_location_of_order_items', 10, 3 );
function storage_location_of_order_items( $item_id, $item, $product ){
    // Only on backend order edit pages
    if( ! ( is_admin() && $item->is_type('line_item') ) ) return;

    // Get your ACF product value (replace the slug by yours below)
    if( $acf_value = get_field( 'BinLocation', $product->get_id() ) ) {
        $acf_label = __('Stored in: ');

        // Outputing the value of the "location storage" for this product item
        echo '<div class="wc-order-item-custom"><strong>' . $acf_value .  $acf_label . '</strong></div>';
    }
}
add_action('woocommerce_-before_-order_-itemmeta','storage_-location_-of_-order_-items',10,3);
功能存储\u订单\u项的位置\u($item\u id,$item,$product){
//仅在后端订单编辑页面上
if(!(is_admin()&&&$item->is_type('line_item'))返回;
//获得你的ACF产品价值(用你的替换下面的slug)
如果($acf\u value=get\u字段('BinLocation',$product->get\u id()){
$acf_标签=_('存储在:');
//输出此产品项的“位置存储”值
回显“”。$acf\U值。$acf\U标签。“”;
}
}
代码可以放在活动子主题(或主题)的任何php文件中,也可以放在任何插件php文件中

这段代码经过测试,可以在WooCommerce版本3及更高版本中使用



您好,在wc 3.5中,这似乎不起作用,它显示字段,但随后停止呈现其余订单信息、发货和总计?有什么想法吗?您好,在wc 3.5中,这似乎不起作用,它显示字段,但随后停止呈现其余的订单信息、发货和总计?有什么想法吗?