added rating meta box for comments, fix #4072
This commit is contained in:
parent
9a82aecaad
commit
e04dadd8d9
|
@ -43,6 +43,9 @@ class WC_Admin_Meta_Boxes {
|
|||
// Save Coupon Meta Boxes
|
||||
add_action( 'woocommerce_process_shop_coupon_meta', 'WC_Meta_Box_Coupon_Data::save', 10, 2 );
|
||||
|
||||
// Save Rating Meta Boxes
|
||||
add_action( 'comment_edit_redirect', 'WC_Meta_Box_Order_Reviews::save', 1, 2 );
|
||||
|
||||
// Error handling (for showing errors from meta boxes on next page load)
|
||||
add_action( 'admin_notices', array( $this, 'output_errors' ) );
|
||||
add_action( 'shutdown', array( $this, 'save_errors' ) );
|
||||
|
@ -100,6 +103,10 @@ class WC_Admin_Meta_Boxes {
|
|||
|
||||
// Coupons
|
||||
add_meta_box( 'woocommerce-coupon-data', __( 'Coupon Data', 'woocommerce' ), 'WC_Meta_Box_Coupon_Data::output', 'shop_coupon', 'normal', 'high' );
|
||||
|
||||
// Reviews
|
||||
if ( 'comment' == get_current_screen()->id && isset( $_GET['c'] ) && 'product' == get_post_type( intval( $_GET['c'] ) ) )
|
||||
add_meta_box( 'woocommerce-rating', __( 'Rating', 'woocommerce' ), 'WC_Meta_Box_Order_Reviews::output', 'comment', 'normal', 'high' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* Order Reviews
|
||||
*
|
||||
* Functions for displaying the order reviews data meta box.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Admin
|
||||
* @package WooCommerce/Admin/Meta Boxes
|
||||
* @version 2.1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* WC_Meta_Box_Order_Reviews
|
||||
*/
|
||||
class WC_Meta_Box_Order_Reviews {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $comment ) {
|
||||
global $post_type;
|
||||
|
||||
echo $post_type;
|
||||
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 = 0; $rating <= 5; $rating++ ) {
|
||||
echo sprintf( '<option value="%1$s"%2$s>%1$s</option>', $rating, selected( $current, $rating, false ) );
|
||||
} ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $location, $comment_id ) {
|
||||
// Not allowed, return regular value without updating meta
|
||||
if ( ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) && ! isset( $_POST['rating'] ) )
|
||||
return $location;
|
||||
|
||||
// Update meta
|
||||
update_comment_meta(
|
||||
$comment_id,
|
||||
'rating',
|
||||
intval( $_POST['rating'] )
|
||||
);
|
||||
|
||||
// Return regular value after updating
|
||||
return $location;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue