gpt4 book ai didi

php - Woocommerce 管理员订单详细信息 - 在订单详细信息页面上显示自定义数据

转载 作者:可可西里 更新时间:2023-10-31 22:44:55 24 4
gpt4 key购买 nike

我正在搜索并尝试了 2 天,但没有成功,请帮助。

我想过滤 woocommerce 订单以根据产品属性从 db 添加更多详细信息到订单详细信息页面,但我找不到适合此任务的 woocommerce 操作/过滤器 Hook 。这里假设我有变量 $is_customized = false;

如果 $is_customized == true 那么我需要将自定义数据从数据库添加到订单详细信息页面。

注意:我不想添加额外的元框,而是想更改订单明细表:

  • 用存储在数据库中的图像替换默认的产品图像并且,
  • 在产品名称下方添加一个包含自定义属性的 div。

我的变量中有所有这些值,但我不知道应该使用哪个操作 Hook 。

我附上了一张图片以供说明。

enter image description here

只需要知道我是否可以更改/过滤这些订单结果以及如何更改/过滤?

非常感谢您抽出时间提供帮助。谢谢

最佳答案

下面是如何在 woocommerce_before_order_itemmeta 上显示一些额外数据的开始钩子(Hook):

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>';
}

我不知道你是如何保存你的数据的,所以我不能给出更准确的建议。请记住,在该 Hook 之后,您保存为订单项元的任何内容都会自动显示。

过滤图像比较困难。我找到了这个 gist作为开始,但它需要一些自定义条件逻辑,因为您不想在任何地方过滤缩略图,而只是按顺序过滤。

编辑:目前我能做的最好的过滤项目缩略图:

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;
}

关于php - Woocommerce 管理员订单详细信息 - 在订单详细信息页面上显示自定义数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32457241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com