WC_Comments::add_comment_rating()public staticWC 1.0

Rating field for comments.

Method of the class: WC_Comments{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Comments::add_comment_rating( $comment_id );
$comment_id(int) (required)
Comment ID.

WC_Comments::add_comment_rating() code WC 8.7.0

public static function add_comment_rating( $comment_id ) {
	if ( isset( $_POST['rating'], $_POST['comment_post_ID'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) ) { // WPCS: input var ok, CSRF ok.
		if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) { // WPCS: input var ok, CSRF ok, sanitization ok.
			return;
		}
		add_comment_meta( $comment_id, 'rating', intval( $_POST['rating'] ), true ); // WPCS: input var ok, CSRF ok.

		$post_id = isset( $_POST['comment_post_ID'] ) ? absint( $_POST['comment_post_ID'] ) : 0; // WPCS: input var ok, CSRF ok.
		if ( $post_id ) {
			self::clear_transients( $post_id );
		}
	}
}