diff --git a/includes/admin/class-wc-admin-meta-boxes.php b/includes/admin/class-wc-admin-meta-boxes.php index e70a1cbafd9..81fced20a5d 100644 --- a/includes/admin/class-wc-admin-meta-boxes.php +++ b/includes/admin/class-wc-admin-meta-boxes.php @@ -65,7 +65,7 @@ class WC_Admin_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_Product_Reviews::save', 1, 2 ); + add_filter( 'wp_update_comment_data', 'WC_Meta_Box_Product_Reviews::save', 1 ); // Error handling (for showing errors from meta boxes on next page load). add_action( 'admin_notices', array( $this, 'output_errors' ) ); diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php b/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php index 2149441c93a..0c57be63a7e 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-reviews.php @@ -40,17 +40,22 @@ class WC_Meta_Box_Product_Reviews { /** * Save meta box data * - * @param mixed $location - * @param int $comment_id + * @param mixed $data * * @return mixed */ - public static function save( $location, $comment_id ) { + public static function save( $data ) { // Not allowed, return regular value without updating meta if ( ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) && ! isset( $_POST['rating'] ) ) { - return $location; + return $data; } + if ( $_POST['rating'] > 5 || $_POST['rating'] < 0 ) { + return $data; + } + + $comment_id = $data['comment_ID']; + // Update meta update_comment_meta( $comment_id, @@ -59,6 +64,6 @@ class WC_Meta_Box_Product_Reviews { ); // Return regular value after updating - return $location; + return $data; } }