WC_Meta_Box_Product_Reviews

WC_Meta_Box_Product_Reviews.

Defined (1)

The class is defined in the following location(s).

/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php  
  1. class WC_Meta_Box_Product_Reviews { 
  2.  
  3. /** 
  4. * Output the metabox 
  5. */ 
  6. public static function output( $comment ) { 
  7. wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' ); 
  8.  
  9. $current = get_comment_meta( $comment->comment_ID, 'rating', true ); 
  10. ?> 
  11. <select name="rating" id="rating"> 
  12. <?php for ( $rating = 1; $rating <= 5; $rating ++ ) { 
  13. printf( '<option value="%1$s"%2$s>%1$s</option>', $rating, selected( $current, $rating, false ) ); 
  14. } ?> 
  15. </select> 
  16. <?php 
  17.  
  18. /** 
  19. * Save meta box data 
  20. */ 
  21. public static function save( $location, $comment_id ) { 
  22. // Not allowed, return regular value without updating meta 
  23. if ( ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) && ! isset( $_POST['rating'] ) ) 
  24. return $location; 
  25.  
  26. // Update meta 
  27. update_comment_meta( 
  28. $comment_id,  
  29. 'rating',  
  30. intval( $_POST['rating'] ) 
  31. ); 
  32.  
  33. // Return regular value after updating 
  34. return $location;