1 <?php
 2 /**
 3  * Order Reviews
 4  *
 5  * Functions for displaying the order reviews data meta box.
 6  *
 7  * @author      WooThemes
 8  * @category    Admin
 9  * @package     WooCommerce/Admin/Meta Boxes
10  * @version     2.1.0
11  */
12 
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14 
15 /**
16  * WC_Meta_Box_Order_Reviews
17  */
18 class WC_Meta_Box_Order_Reviews {
19 
20     /**
21      * Output the metabox
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      * Save meta box data
38      */
39     public static function save( $location, $comment_id ) {
40         // Not allowed, return regular value without updating meta
41         if ( ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) && ! isset( $_POST['rating'] ) ) {
42             return $location;
43         }
44 
45         // Update meta
46         update_comment_meta(
47             $comment_id,
48             'rating',
49             intval( $_POST['rating'] )
50         );
51 
52         // Return regular value after updating
53         return $location;
54     }
55 }
56 
WooCommerce API documentation generated by ApiGen 2.8.0