Domanda

Negli ultimi anni ci sono stati molti thread e argomenti su come creare un tipo di commento personalizzato. Per la maggior parte ho capito che è possibile (perché WooCommerce lo fa) ma consigliato di usare comment_meta invece.

La mia domanda è come wooCommerce aggiunge il comment_type di order_note al menu a discesa nell'amministrazione dei commenti?

Un regrex del codice di WooCommerce non presenta nulla di utile. Qualsiasi direzione è apprezzata.

Esempio di aggiunta di un commento con il tipo di order_note:

/**
 * Adds a note (comment) to the order
 *
 * @access public
 * @param string $note Note to add
 * @param int $is_customer_note (default: 0) Is this a note for the customer?
 * @return id Comment ID
 *
 * *file is class-wp-order.php*
 */
public function add_order_note( $note, $is_customer_note = 0 ) {

    $is_customer_note = intval( $is_customer_note );

    if ( is_user_logged_in() && current_user_can( 'manage_woocommerce' ) ) {
        $user                 = get_user_by( 'id', get_current_user_id() );
        $comment_author       = $user->display_name;
        $comment_author_email = $user->user_email;
    } else {
        $comment_author       = __( 'WooCommerce', 'woocommerce' );
        $comment_author_email = strtolower( __( 'WooCommerce', 'woocommerce' ) ) . '@';
        $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
        $comment_author_email = sanitize_email( $comment_author_email );
    }

    $comment_post_ID        = $this->id;
    $comment_author_url     = '';
    $comment_content        = $note;
    $comment_agent          = 'WooCommerce';
    $comment_type           = 'order_note';
    $comment_parent         = 0;
    $comment_approved       = 1;
    $commentdata            = apply_filters( 'woocommerce_new_order_note_data', compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_agent', 'comment_type', 'comment_parent', 'comment_approved' ), array( 'order_id' => $this->id, 'is_customer_note' => $is_customer_note ) );

    $comment_id = wp_insert_comment( $commentdata );

    add_comment_meta( $comment_id, 'is_customer_note', $is_customer_note );

    if ( $is_customer_note )
        do_action( 'woocommerce_new_customer_note', array( 'order_id' => $this->id, 'customer_note' => $note ) );

    return $comment_id;
}

Domanda precedente: il progetto su cui sto lavorando in questo momento sarebbe molto, molto più facile se potessi solo aggiungere un comment_type inoltre comment_meta ove opportuno. La mia domanda è dove dovrei cercare una guida/esempio su come farlo?

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top