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

Output a product custom field in WooCommerce Order Admin Page (ACF)

使用 WooCommerce,我使用 Advanced Custom Fields plugin 来跟踪我实际存储每个产品的位置。

收到订单时,我希望能够查看管理员编辑订单页面并查看商品的存储位置。这样我就可以抓起来发货了。

这是我想看的图片:

希望这是有道理的。

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

谢谢。

更新: 使用自定义函数 hoked in woocommerce_before_order_itemmeta action hook,你将能够实现你想要的寻找:

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>';
    }
}

代码进入您的活动子主题(或主题)的任何 php 文件或任何插件 php 文件。

此代码已经过测试并适用于 WooCommerce 版本 3 及更高版本…