2016-12-12 13:00:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Product Reviews
|
|
|
|
*
|
|
|
|
* Functions for displaying product reviews data meta box.
|
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category Admin
|
|
|
|
* @package WooCommerce/Admin/Meta Boxes
|
|
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WC_Meta_Box_Product_Reviews
|
|
|
|
*/
|
|
|
|
class WC_Meta_Box_Product_Reviews {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output the metabox
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param object $comment
|
2016-12-12 13:00:08 +00:00
|
|
|
*/
|
|
|
|
public static function output( $comment ) {
|
|
|
|
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
|
|
|
|
|
|
|
|
$current = get_comment_meta( $comment->comment_ID, 'rating', true );
|
|
|
|
?>
|
|
|
|
<select name="rating" id="rating">
|
|
|
|
<?php for ( $rating = 1; $rating <= 5; $rating ++ ) {
|
2017-03-13 05:39:46 +00:00
|
|
|
printf( '<option value="%1$s"%2$s>%1$s</option>', $rating, selected( $current, $rating, false ) );
|
2016-12-12 13:00:08 +00:00
|
|
|
} ?>
|
|
|
|
</select>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save meta box data
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
|
|
|
* @param mixed $location
|
|
|
|
* @param int $comment_id
|
|
|
|
*
|
|
|
|
* @return mixed
|
2016-12-12 13:00:08 +00:00
|
|
|
*/
|
|
|
|
public static function save( $location, $comment_id ) {
|
|
|
|
// Not allowed, return regular value without updating meta
|
2017-03-07 20:24:24 +00:00
|
|
|
if ( ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) && ! isset( $_POST['rating'] ) ) {
|
2016-12-12 13:00:08 +00:00
|
|
|
return $location;
|
2017-03-07 20:24:24 +00:00
|
|
|
}
|
2016-12-12 13:00:08 +00:00
|
|
|
|
|
|
|
// Update meta
|
|
|
|
update_comment_meta(
|
|
|
|
$comment_id,
|
|
|
|
'rating',
|
|
|
|
intval( $_POST['rating'] )
|
|
|
|
);
|
|
|
|
|
|
|
|
// Return regular value after updating
|
|
|
|
return $location;
|
|
|
|
}
|
|
|
|
}
|