[英]How to Add automatically notes into woocommerce single order page
我想在单个订单页面中自动添加“自定义注释”,其中包含订购产品的一些详细信息(如类别)。
是否可以使用function.php中的函数?
是的,这是可能的。 您需要在当前主题的functions.php文件中添加以下代码。
function wdm_my_custom_notes_on_single_order_page($order){
$category_array=array();
foreach( $order->get_items() as $item_id => $item ) {
$product_id=$item['product_id'];
$product_cats = wp_get_post_terms( $product_id, 'product_cat' );
foreach( $product_cats as $key => $value ){
if(!in_array($value->name,$category_array)){
array_push($category_array,$value->name);
}
}
}
$note = '<b>Categories of products in this Order : </b>'.implode(' , ',$category_array);
echo $note;
$order->add_order_note( $note );
}
add_action( 'woocommerce_order_details_after_order_table', 'wdm_my_custom_notes_on_single_order_page',10,1 );
输出:
您可以自定义此功能以满足其他要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.