![](/img/trans.png)
[英]Display product custom field in WooCommerce Order admin Page (ACF)
[英]Output a product custom field in WooCommerce Order Admin Page (ACF)
使用 WooCommerce,我使用高级自定义字段插件来跟踪我实际存储每个产品的位置。
收到订单后,我希望能够查看管理员编辑订单页面并查看商品的存储位置。 所以我可以抓住它来运送。
这是我想看到的图片:
希望这是有道理的。
我只想在 Wordpress 的编辑订单管理页面上为每个产品调用单个产品 ACF 变量 (BinLocation)。 对此有什么帮助吗?
谢谢。
更新:使用woocommerce_before_order_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>';
}
}
代码位于活动子主题(或主题)的任何 php 文件或任何插件 php 文件中。
此代码已在 WooCommerce 版本 3 及更高版本中进行了测试和工作……
上面的答案非常适合简单的产品。 以下内容也将返回父级的自定义字段以进行变体。 但是,它不允许自定义字段对于每个变体都不同。
add_action( 'woocommerce_before_order_itemmeta', 'downloadable_items', 100, 3 );
function downloadable_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 ( $product->is_type( 'simple' ) ) {
if ( $acf_value = get_field( 'downloadable_image', $product->get_id() ) ) {
$acf_label = __('Download Link: ');
// Outputing the value of the "downloadable item" for this product item
echo '<div class="wc-order-item-custom">' . $acf_label .'<a href="'. $acf_value
.'">'. $acf_value . '</a></div>';
}} else {
if ( $acf_value = get_field( 'downloadable_image', $product->get_parent_id() ) ) {
$acf_label = __('Download Link: ');
// Outputing the value of the "downloadable item" for this product item
echo '<div class="wc-order-item-custom">' . $acf_label .'<a href="'. $acf_value
.'">'. $acf_value . '</a></div>';
}}
}
希望这对其他人有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.