[英]Woocommerce Admin Order Details - Show custom data on order details page
我正在搜索並嘗試2天但沒有成功,請幫忙。
我想過濾woocommerce訂單,根據產品屬性從db到訂單詳細信息頁面添加其他詳細信息,但我無法找到適合此任務的正確的woocommerce操作/過濾器掛鈎。 這里假設我變量$is_customized = false
;
如果$is_customized == true
那么我需要將數據庫中的自定義數據添加到訂單詳細信息頁面。
注意:我不想添加其他元框而是要更改訂單明細表:
我在變量中有所有這些值,但我無法弄清楚應該使用哪個動作鈎子。
我附上了一張圖片以便澄清。
只需要知道我是否可以更改/過濾這些訂單結果以及如何?
感謝您的時間和幫助。 謝謝
以下是如何在woocommerce_before_order_itemmeta
鈎子上顯示一些額外數據的woocommerce_before_order_itemmeta
:
add_action( 'woocommerce_before_order_itemmeta', 'so_32457241_before_order_itemmeta', 10, 3 );
function so_32457241_before_order_itemmeta( $item_id, $item, $_product ){
echo '<p>bacon</p>';
}
我不知道你是如何保存你的數據的,所以我無法提出更准確的建議。 請記住,在該掛鈎之后,您保存為訂單商品元的任何內容都將自動顯示。
過濾圖像更加困難。 我發現這個要點是一個開始,但它需要一些自定義條件邏輯,因為你不想在任何地方過濾縮略圖,而只是在訂單中。
編輯:目前我可以做的最好的過濾項目縮略圖:
add_filter( 'get_post_metadata', 'so_32457241_order_thumbnail', 10, 4 );
function so_32457241_order_thumbnail( $value, $post_id, $meta_key, $single ) {
// We want to pass the actual _thumbnail_id into the filter, so requires recursion
static $is_recursing = false;
// Only filter if we're not recursing and if it is a post thumbnail ID
if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) {
$is_recursing = true; // prevent this conditional when get_post_thumbnail_id() is called
$value = get_post_thumbnail_id( $post_id );
$is_recursing = false;
$value = apply_filters( 'post_thumbnail_id', $value, $post_id ); // yay!
if ( ! $single ) {
$value = array( $value );
}
}
return $value;
}
add_filter( 'post_thumbnail_id', 'so_custom_order_item_thumbnail', 10, 2 );
function so_custom_order_item_thumbnail( $id, $post_id ){
if( is_admin() ){
$screen = get_current_screen();
if( $screen->base == 'post' && $screen->post_type == 'shop_order' ){
// this gets you the shop_order $post object
global $post;
// no really *good* way to check post item, but could possibly save
// some kind of array in the order meta
$id = 68;
}
}
return $id;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.