1 <?php
2 3 4 5 6 7 8 9 10 11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17
18 class WC_Meta_Box_Order_Reviews {
19
20 21 22
23 public static function output( $comment ) {
24 wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
25
26 $current = get_comment_meta( $comment->comment_ID, 'rating', true );
27 ?>
28 <select name="rating" id="rating">
29 <?php for ( $rating = 0; $rating <= 5; $rating++ ) {
30 echo sprintf( '<option value="%1$s"%2$s>%1$s</option>', $rating, selected( $current, $rating, false ) );
31 } ?>
32 </select>
33 <?php
34 }
35
36 37 38
39 public static function save( $location, $comment_id ) {
40
41 if ( ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) && ! isset( $_POST['rating'] ) ) {
42 return $location;
43 }
44
45
46 update_comment_meta(
47 $comment_id,
48 'rating',
49 intval( $_POST['rating'] )
50 );
51
52
53 return $location;
54 }
55 }
56