我正在寻找代码,使我能够收集WooCommerce产品的明星评论,而无需用户提供任何评论。
下面的这段代码通过消除评论框让我走了那么远,但WordPress不允许保存提交内容。这段代码缺少什么吗?
function filter_woocommerce_product_review_comment_form_args( $comment_form ) { if ( function_exists( 'WC' ) && is_product() ) { $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'your-theme-text-domain' ) . '</label><select name="rating" id="rating" required> <option value="">' . esc_html__( 'Rate…', 'your-theme-text-domain' ) . '</option> <option value="5">' . esc_html__( 'Perfect', 'your-theme-text-domain' ) . '</option> <option value="4">' . esc_html__( 'Good', 'your-theme-text-domain' ) . '</option> <option value="3">' . esc_html__( 'Average', 'your-theme-text-domain' ) . '</option> <option value="2">' . esc_html__( 'Not that bad', 'your-theme-text-domain' ) . '</option> <option value="1">' . esc_html__( 'Very poor', 'your-theme-text-domain' ) . '</option> </select></div>'; $comment_form['fields']['author'] = ''; $comment_form['fields']['email'] = ''; $comment_form['fields']['url'] = ''; $comment_form['comment_notes_before'] = ''; $comment_form['label_submit'] = esc_html__( 'Submit Review', 'your-theme-text-domain' ); $comment_form['title_reply'] = esc_html__( 'Leave a Review', 'your-theme-text-domain' ); } return $comment_form; } add_filter( 'woocommerce_product_review_comment_form_args', 'filter_woocommerce_product_review_comment_form_args' );