[英]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.