Hai*_*eed 11 php wordpress wordpress-plugin content-management-system woocommerce
我正在搜索并尝试2天但没有成功,请帮忙.
我想过滤woocommerce订单,根据产品属性从db到订单详细信息页面添加其他详细信息,但我无法找到适合此任务的正确的woocommerce操作/过滤器挂钩.这里假设我变量$is_customized = false;
如果$is_customized == true那时我需要从数据库添加自定义数据到订单详细信息页面.
注意:我不想添加其他元框而是要更改订单明细表:
我在变量中有所有这些值,但我无法弄清楚应该使用哪个动作钩子.
我附上了一张图片以便澄清.
只需要知道我是否可以更改/过滤这些订单结果以及如何?
感谢您的时间和帮助.谢谢
hel*_*ing 15
以下是如何在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>';
}
Run Code Online (Sandbox Code Playgroud)
我不知道你是如何保存你的数据的,所以我无法提出更准确的建议.请记住,在该挂钩之后,您保存为订单商品元的任何内容都将自动显示.
过滤图像更加困难.我发现这个要点是一个开始,但它需要一些自定义的条件逻辑,因为你不想在任何地方过滤缩略图,而只是在订单中.
编辑:目前我可以做的最好的过滤项目缩略图:
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12794 次 |
| 最近记录: |