added rating meta box for comments, fix #4072

This commit is contained in:
claudiosmweb 2013-11-08 17:19:42 -02:00
parent 9a82aecaad
commit e04dadd8d9
2 changed files with 70 additions and 6 deletions

View File

@ -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' ) );
@ -93,13 +96,17 @@ class WC_Admin_Meta_Boxes {
// Orders
add_meta_box( 'woocommerce-order-data', __( 'Order Data', 'woocommerce' ), 'WC_Meta_Box_Order_Data::output', 'shop_order', 'normal', 'high' );
add_meta_box( 'woocommerce-order-items', __( 'Order Items', 'woocommerce' ), 'WC_Meta_Box_Order_Items::output', 'shop_order', 'normal', 'high' );
add_meta_box( 'woocommerce-order-totals', __( 'Order Totals', 'woocommerce' ), 'WC_Meta_Box_Order_Totals::output', 'shop_order', 'side', 'default');
add_meta_box( 'woocommerce-order-notes', __( 'Order Notes', 'woocommerce' ), 'WC_Meta_Box_Order_Notes::output', 'shop_order', 'side', 'default');
add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable Product Permissions', 'woocommerce' ) . ' <span class="tips" data-tip="' . __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) . '">[?]</span>', 'WC_Meta_Box_Order_Downloads::output', 'shop_order', 'normal', 'default');
add_meta_box( 'woocommerce-order-actions', __( 'Order Actions', 'woocommerce' ), 'WC_Meta_Box_Order_Actions::output', 'shop_order', 'side', 'high');
add_meta_box( 'woocommerce-order-totals', __( 'Order Totals', 'woocommerce' ), 'WC_Meta_Box_Order_Totals::output', 'shop_order', 'side', 'default' );
add_meta_box( 'woocommerce-order-notes', __( 'Order Notes', 'woocommerce' ), 'WC_Meta_Box_Order_Notes::output', 'shop_order', 'side', 'default' );
add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable Product Permissions', 'woocommerce' ) . ' <span class="tips" data-tip="' . __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) . '">[?]</span>', 'WC_Meta_Box_Order_Downloads::output', 'shop_order', 'normal', 'default' );
add_meta_box( 'woocommerce-order-actions', __( 'Order Actions', 'woocommerce' ), 'WC_Meta_Box_Order_Actions::output', 'shop_order', 'side', 'high' );
// Coupons
add_meta_box( 'woocommerce-coupon-data', __( 'Coupon Data', 'woocommerce' ), 'WC_Meta_Box_Coupon_Data::output', 'shop_coupon', 'normal', 'high');
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' );
}
/**
@ -154,4 +161,4 @@ class WC_Admin_Meta_Boxes {
}
new WC_Admin_Meta_Boxes();
new WC_Admin_Meta_Boxes();

View File

@ -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;
}
}