以下是如何在
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 ) {
static $is_recursing = false;
if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) {
$is_recursing = true;
$value = get_post_thumbnail_id( $post_id );
$is_recursing = false;
$value = apply_filters( 'post_thumbnail_id', $value, $post_id );
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' ){
global $post;
$id = 68;
}
}
return $id;
}
manage $post type posts columns
和manage $post type posts custom column
进行处理。在订单的情况下,文章类型为shop_order
。 - helgathevikinghtml-order-items.php
和html-order-item.php
中看到可用的钩子。 - helgatheviking