WC_AJAX::add_order_note()

Add order note via ajax.


Description Description


Source Source

File: includes/class-wc-ajax.php

1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
public static function add_order_note() {
    check_ajax_referer( 'add-order-note', 'security' );
 
    if ( ! current_user_can( 'edit_shop_orders' ) || ! isset( $_POST['post_id'], $_POST['note'], $_POST['note_type'] ) ) {
        wp_die( -1 );
    }
 
    $post_id   = absint( $_POST['post_id'] );
    $note      = wp_kses_post( trim( wp_unslash( $_POST['note'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    $note_type = wc_clean( wp_unslash( $_POST['note_type'] ) );
 
    $is_customer_note = ( 'customer' === $note_type ) ? 1 : 0;
 
    if ( $post_id > 0 ) {
        $order      = wc_get_order( $post_id );
        $comment_id = $order->add_order_note( $note, $is_customer_note, true );
        $note       = wc_get_order_note( $comment_id );
 
        $note_classes   = array( 'note' );
        $note_classes[] = $is_customer_note ? 'customer-note' : '';
        $note_classes   = apply_filters( 'woocommerce_order_note_class', array_filter( $note_classes ), $note );
        ?>
        <li rel="<?php echo absint( $note->id ); ?>" class="<?php echo esc_attr( implode( ' ', $note_classes ) ); ?>">
            <div class="note_content">
                <?php echo wp_kses_post( wpautop( wptexturize( make_clickable( $note->content ) ) ) ); ?>
            </div>
            <p class="meta">
                <abbr class="exact-date" title="<?php echo esc_attr( $note->date_created->date( 'y-m-d h:i:s' ) ); ?>">
                    <?php
                    /* translators: $1: Date created, $2 Time created */
                    printf( esc_html__( 'added on %1$s at %2$s', 'woocommerce' ), esc_html( $note->date_created->date_i18n( wc_date_format() ) ), esc_html( $note->date_created->date_i18n( wc_time_format() ) ) );
                    ?>
                </abbr>
                <?php
                if ( 'system' !== $note->added_by ) :
                    /* translators: %s: note author */
                    printf( ' ' . esc_html__( 'by %s', 'woocommerce' ), esc_html( $note->added_by ) );
                endif;
                ?>
                <a href="#" class="delete_note" role="button"><?php esc_html_e( 'Delete note', 'woocommerce' ); ?></a>
            </p>
        </li>
        <?php
    }
    wp_die();
}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.