在过去几年中,有许多关于如何创建自定义注释类型的线程和主题。大部分情况下,我认为这是可能的(因为WooCommerce做到了),但建议使用comment_meta
相反
我的问题是WooCommerce如何添加comment_type
属于order_note
评论管理下拉列表?
对WooCommerce代码的重新修订没有任何帮助。欢迎任何指示。
添加类型为的注释的示例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;
}
上一个问题:如果我可以添加一个comment_type
除了comment_meta
在适当的情况下。我的问题是,我应该在哪里寻找如何做到这一点的指南/示例