php - 如何在 woocommerce 的查看订单页面中自定义订单备注
问题描述
请你能帮我找到如何编辑系统生成的自动订单注释(与通过订单更改的项目有关)我找不到它的文件
我想做的事
- 在已删除项目旁边添加数量(如果我有 10 件订单并且我已经删除了 3 个,我想查看订单备注中删除的数量
- 删除或添加后合计
解决方案
试试这个:
解决方案 1:
在结帐时添加订单备注
add_filter( 'woocommerce_checkout_fields', 'woo_custom_order_notes_checkout_fields' );
function woo_custom_order_notes_checkout_fields( $fields )
{
$fields['order']['order_comments']['placeholder'] = 'Your Special notes';
$fields['order']['order_comments']['label'] = 'Add your special note txt';
return $fields;
}
当您使用自定义文本下订单并下订单后,您将能够在仪表板上的订单详细信息/编辑订单中查看自定义订单备注。
解决方案2:
单击更新按钮后,获取/打印订单查看/编辑页面上的所有注释。
// order comment/notes by id
function woo_get_comment_by_id( $comment_id ) {
$comment = get_comment( intval( $comment_id ) );
if ( ! empty( $comment ) ) {
return $comment->comment_content;
} else {
return '';
}
}
add_action( 'save_post_shop_order', 'wpo_wcol_order_notes', 10, 1 );
function wpo_wcol_order_notes ( $order_id ) {
$args = array(
'post_id' => $order_id,
'orderby' => 'comment_ID',
'order' => 'DESC',
'type' => 'order_note',
// 'number' => 1
);
remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
$notes = get_comments( $args );
if($notes){
foreach($notes as $note){
$comment_id = $note->comment_ID ?:0;
if( $comment_id ){
echo woo_get_comment_by_id( $comment_id ).'<br>';
}
}
}
exit; // after test you should removed
add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
}
您还可以根据要求相应地更改操作“save_post_shop_order”。
推荐阅读
- r - 在 R 中创建具有特定迭代的列表
- protractor - 无法通过字符串名称定位元素
- powershell - 使用 PowerCLI 获取当前 CPU 使用率
- go - 为什么在达到之前的容量限制时,切片的容量会增加一倍?
- javascript - Redux 中间件工作一半但未完全取消操作
- python - Python:如何用数据框中的条件替换 NaN?
- nginx-config - nginx 配置 - 否定条件
- android - 世博会推送通知 - 错误:无法获取设备的 GCM 令牌
- cntk - CNTK LSTM 输入形状
- ibm-integration-bus - 由于从 IBM Integration Bus 工作区中删除 GeneratedBarFiles 文件夹而导致部署库时出现问题