问题描述
通过WooCommerce,我正在使用来跟踪我实际存储的位置每个产品。
With WooCommerce, I'm using the Advanced Custom Fields plugin to keep a track of where I physically store each product.
收到订单时,我希望能够查看admin编辑订单页面,并查看项目的存储位置。所以我可以抓住它发货。
When an order comes in, I want to be able to look at the admin edit order page and see where the items are stored. So I can grab it to ship.
这是我想看到的图片:
希望如此。
我只想在Wordpress的编辑订单管理页面上为每个产品调用单个产品ACF变量(BinLocation)。对此有任何帮助吗?
I just want to recall the individual product ACF variable (BinLocation) for each product on the Edit Order Admin Page for Wordpress. Any help on this?
谢谢。
推荐答案
更新:使用在 woocommerce_before_order_itemmeta
操作挂钩中附加的自定义函数,您将能够实现所需的功能:
Updated: Using a custom function hoocked in woocommerce_before_order_itemmeta
action hook, you will be able to achieve what you are looking for:
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及更高版本中使用。
This code is tested and works in WooCommerce version 3 and up…
这篇关于在WooCommerce订单管理页面(ACF)中输出产品自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!