【问题标题】:how to customise order notes in view order page in woocommerce如何在 woocommerce 的查看订单页面中自定义订单备注
【发布时间】:2021-10-28 00:07:56
【问题描述】:

请你帮我找 如何编辑系统生成的自动订单备注(与通过订单更改的项目相关)我找不到它的文件

我想做什么

  • 在已删除项目旁边添加数量(如果我有 10 件订单并且我已经删除了 3 件,我想查看订单备注中删除的数量
  • 删除或添加后合计

【问题讨论】:

  • 嗨!到目前为止,您尝试过什么?
  • 我是 ios 开发人员,我自己的应用程序基于 woocommerce apis,我真的不是 php 开发人员,所以我查找了我猜它应该包含此功能的文件,以猜测我应该怎么做,但我没有得到它,所以我寻求帮助---并在询问之前进行了很多搜索:)
  • 听起来你需要一个 PHP 开发人员。由于我们不是免费的编码服务,您可以在 Fiverr 上聘请 PHP WordPress 开发人员!很抱歉让你失望了,但我只是在遵守这里的规则。
  • 谢谢,我找到了一份工作,我会在这里分享结果,谢谢你的支持:)

标签: php woocommerce code-snippets


【解决方案1】:

试试这个: 解决方案 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”。

【讨论】:

  • 截图来自管理仪表板的订单。您建议的过滤器是结帐的一部分。
  • 感谢您的回答,但我认为您错过了它不属于结帐的问题
  • @MahmoudQatamsh 是的,但根据我们的理解,结帐说明将显示在仪表板订单视图/编辑页面上。
猜你喜欢
  • 2015-11-21
  • 1970-01-01
  • 2018-07-17
  • 1970-01-01
  • 1970-01-01
  • 2018-10-19
  • 2017-01-20
  • 1970-01-01
  • 2018-07-12
相关资源
最近更新 更多