Return comment_meta in get_comments with WooCommerce

I have set up my custom comment_meta like so:

function save_comment_meta_data( $comment_id ) {
add_comment_meta( $comment_id, ‘comment_title’, $_POST[ ‘comment_title’ ] );
}
add_action(‘comment_post’, ‘save_comment_meta_data’);

I have my form set up as so:

$comment_form = [
‘label_submit’ => __( ‘Submit Review’, ‘woocommerce’ ),
‘comment_field’ => ”,
];
$comment_form[‘comment_field’] .= ‘<p class=”comment-form-comment”><label for=”comment_title”>’ . esc_html__( ‘Review Title’, ‘woocommerce’ ) . ‘ <span class=”required”>*</span></label><input id=”comment_title” name=”comment_title” width=”99″ aria-required=”true” required></p>’;

$comment_form[‘comment_field’] .= ‘<p class=”comment-form-comment”><label for=”comment”>’ . esc_html__( ‘Your Name’, ‘woocommerce’ ) . ‘ <span class=”required”>*</span></label><input id=”comment” name=”comment” width=”99″ aria-required=”true” required></p>’;

$comment_form[‘comment_field’] .= ‘<p class=”comment-form-comment”><label for=”comment”>’ . esc_html__( ‘Your Review Comments’, ‘woocommerce’ ) . ‘ <span class=”required”>*</span></label><textarea id=”comment” name=”comment” cols=”45″ rows=”8″ aria-required=”true” required></textarea></p>’;

$comment_form[‘comment_field’] .= ‘<div class=”comment-form-rating”><label for=”rating”>’ . esc_html__( ‘Your rating’, ‘woocommerce’ ) . ‘</label><select name=”rating” id=”rating” aria-required=”true” required>
<option value=””>’ . esc_html__( ‘Rate&hellip;’, ‘woocommerce’ ) . ‘</option>
<option value=”5″>’ . esc_html__( ‘Perfect’, ‘woocommerce’ ) . ‘</option>
<option value=”4″>’ . esc_html__( ‘Good’, ‘woocommerce’ ) . ‘</option>
<option value=”3″>’ . esc_html__( ‘Average’, ‘woocommerce’ ) . ‘</option>
<option value=”2″>’ . esc_html__( ‘Not that bad’, ‘woocommerce’ ) . ‘</option>
<option value=”1″>’ . esc_html__( ‘Very poor’, ‘woocommerce’ ) . ‘</option>
</select></div>’;

//comment_form();
comment_form( apply_filters( ‘woocommerce_product_review_comment_form_args’, $comment_form ) );

When I go to call my comments, I put in the exact comment_meta name to return in my array of comments:

$comments = get_comments( [‘post_type’ => ‘product’, ‘post_id’ => $productID, ‘meta_key’ => ‘comment_title’] );
wp_list_comments( [ ‘callback’ => ‘woocommerce_comments’ ], $comments);

I’m using the callback ‘callback’ => ‘woocommerce_comments’ just so I do not have to deal with getting the star rating and the existing meta passed in.

My hangup is I can’t actually get the comment_title meta into the array. When I var_dump I do not see it, and thus not showing in my wp_list_comments command. I had thought if I pass in the ‘meta_key’ argument I want into wp_list_comments it would include the value. What am I missing here?

Read more here:: Return comment_meta in get_comments with WooCommerce

Leave a Reply

Your email address will not be published. Required fields are marked *