WC_Comments::add_comment_purchase_verification PHP Method

add_comment_purchase_verification() public static method

Determine if a review is from a verified owner at submission.
public static add_comment_purchase_verification ( integer $comment_id ) : boolean
$comment_id integer
return boolean
    public static function add_comment_purchase_verification($comment_id)
    {
        $comment = get_comment($comment_id);
        $verified = false;
        if ('product' === get_post_type($comment->comment_post_ID)) {
            $verified = wc_customer_bought_product($comment->comment_author_email, $comment->user_id, $comment->comment_post_ID);
            add_comment_meta($comment_id, 'verified', (int) $verified, true);
        }
        return $verified;
    }

Usage Example

Exemplo n.º 1
0
/**
 * Get review verification status.
 * @param  int $comment_id
 * @return bool
 */
function wc_review_is_from_verified_owner($comment_id)
{
    $verified = get_comment_meta($comment_id, 'verified', true);
    // If no "verified" meta is present, generate it (if this is a product review).
    if ('' === $verified) {
        $verified = WC_Comments::add_comment_purchase_verification($comment_id);
    }
    return (bool) $verified;
}