как получить публичную заметку клиента только с идентификатором заказа - PullRequest
0 голосов
/ 17 мая 2018

Я пишу плагин, чтобы клиент мог отслеживать статус / детали заказа с помощью order id.

, а также я хочу показать только Примечания общественного порядка для клиента.

но я не могу найти какую-либо функцию или способ сделать это.

вот мой код, но этот код показывает все заметки, включая личные и публичные заметки:

*/
function woohez_get_all_order_notes( $order_id ){
    $order_notes    =   array();
    $args = array (
            'post_id'   => $order_id,
            'orderby'   => 'comment_ID',
            'order'     => 'DESC',
            'approve'   => 'approve',
            'type'      => 'order_note'
    );
    remove_filter ( 'comments_clauses', array (
            'WC_Comments',
            'exclude_order_comments'
    ), 10, 1 );

    $notes = get_comments ( $args );
    if ($notes) {
        foreach ( $notes as $note ) {
            $order_notes[]  = wpautop ( wptexturize ( wp_kses_post ( $note->comment_content ) ) );
        }
    } 

    return $order_notes;
}


$notes_array  =  woohez_get_all_order_notes( 209 );
if ( count( $notes_array ) != 0) {
    foreach ( $notes_array as $notes ){
        echo $notes; 
    }
} else {
    echo "No notes found!";
}

Ответы [ 2 ]

0 голосов
/ 17 мая 2018

Я думаю, что приведенный ниже код получит приватные идентификаторы заметок и исключит их из цикла, так что теперь вы будете получать только заметки, которые не являются приватными

*/
function woohez_get_all_order_notes( $order_id ){
    $private_order_notes = get_private_order_notes( $order_id );
    private_note_ids = array();
    foreach($private_order_notes as $private_note)
    {
           $private_note_ids[] = $private_note['note_id'];
    }
    $order_notes    =   array();
    $args = array (
            'post_id'   => $order_id,
            'orderby'   => 'comment_ID',
            'order'     => 'DESC',
            'approve'   => 'approve',
            'type'      => 'order_note',
            'post__not_in' => $private_note_ids
    );
    remove_filter ( 'comments_clauses', array (
            'WC_Comments',
            'exclude_order_comments'
    ), 10, 1 );

    $notes = get_comments ( $args );
    if ($notes) {
        foreach ( $notes as $note ) {
            $order_notes[]  = wpautop ( wptexturize ( wp_kses_post ( $note->comment_content ) ) );
        }
    } 

    return $order_notes;
}


$notes_array  =  woohez_get_all_order_notes( 209 );
if ( count( $notes_array ) != 0) {
    foreach ( $notes_array as $notes ){
        echo $notes; 
    }
} else {
    echo "No notes found!";
}

function get_private_order_notes( $order_id){
    global $wpdb;

    $table_perfixed = $wpdb->prefix . 'comments';
    $results = $wpdb->get_results("
        SELECT *
        FROM $table_perfixed
        WHERE  `comment_post_ID` = $order_id
        AND  `comment_type` LIKE  'order_note'
    ");

    foreach($results as $note){
        $order_note[]  = array(
            'note_id'      => $note->comment_ID,
            'note_date'    => $note->comment_date,
            'note_author'  => $note->comment_author,
            'note_content' => $note->comment_content,
        );
    }
    return $order_note;
}
0 голосов
/ 17 мая 2018

Я решил проблему, вы должны добавить meta key и meta value, вот так:

function woohez_get_all_order_notes( $orderNumber ){
            $order_notes    =   array();
            $args = array (
                    'post_id'   => $orderNumber,
                    'orderby'   => 'comment_ID',
                    'order'     => 'DESC',
                    'approve'   => 'approve',
                    'type'      => 'order_note',
                    'meta_query' => array(
                        array(
                          'key' => 'is_customer_note',
                          'value' => 1,
                          'compare' => 'EXISTS',
                        )
                      )
            );
            remove_filter ( 'comments_clauses', array (
                    'WC_Comments',
                    'exclude_order_comments'
            ), 10, 1 );

            $notes = get_comments ( $args );
            if ($notes) {
                foreach ( $notes as $note ) {
                    $order_notes[]  = wpautop ( wptexturize ( wp_kses_post ( $note->comment_content ) ) );
                }
            } 

            return $order_notes;
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...