} return $stats; } /** * Make sure WP displays avatars for comments with the `review` type. * @since 2.3 * @param array $comment_types * @return array */ public static function add_avatar_for_review_comment_type($comment_types) { return array_merge($comment_types, array('review')); } /** * Determine if a review is from a verified owner at submission. * @param int $comment_id * @return bool */ 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; } } WC_Comments::init();
/** * Read product data. Can be overridden by child classes to load other props. * * @param WC_Product * @since 2.7.0 */ protected function read_product_data(&$product) { $id = $product->get_id(); if ('' === ($review_count = get_post_meta($id, '_wc_review_count', true))) { WC_Comments::get_review_count_for_product($product); } else { $product->set_review_count($review_count); } if ('' === ($rating_counts = get_post_meta($id, '_wc_rating_count', true))) { WC_Comments::get_rating_counts_for_product($product); } else { $product->set_rating_counts($rating_counts); } if ('' === ($average_rating = get_post_meta($id, '_wc_average_rating', true))) { WC_Comments::get_average_rating_for_product($product); } else { $product->set_average_rating($average_rating); } $product->set_props(array('sku' => get_post_meta($id, '_sku', true), 'regular_price' => get_post_meta($id, '_regular_price', true), 'sale_price' => get_post_meta($id, '_sale_price', true), 'price' => get_post_meta($id, '_price', true), 'date_on_sale_from' => get_post_meta($id, '_sale_price_dates_from', true), 'date_on_sale_to' => get_post_meta($id, '_sale_price_dates_to', true), 'total_sales' => get_post_meta($id, 'total_sales', true), 'tax_status' => get_post_meta($id, '_tax_status', true), 'tax_class' => get_post_meta($id, '_tax_class', true), 'manage_stock' => get_post_meta($id, '_manage_stock', true), 'stock_quantity' => get_post_meta($id, '_stock', true), 'stock_status' => get_post_meta($id, '_stock_status', true), 'backorders' => get_post_meta($id, '_backorders', true), 'sold_individually' => get_post_meta($id, '_sold_individually', true), 'weight' => get_post_meta($id, '_weight', true), 'length' => get_post_meta($id, '_length', true), 'width' => get_post_meta($id, '_width', true), 'height' => get_post_meta($id, '_height', true), 'upsell_ids' => get_post_meta($id, '_upsell_ids', true), 'cross_sell_ids' => get_post_meta($id, '_crosssell_ids', true), 'purchase_note' => get_post_meta($id, '_purchase_note', true), 'default_attributes' => get_post_meta($id, '_default_attributes', true), 'category_ids' => $this->get_term_ids($product, 'product_cat'), 'tag_ids' => $this->get_term_ids($product, 'product_tag'), 'shipping_class_id' => current($this->get_term_ids($product, 'product_shipping_class')), 'virtual' => get_post_meta($id, '_virtual', true), 'downloadable' => get_post_meta($id, '_downloadable', true), 'gallery_image_ids' => array_filter(explode(',', get_post_meta($id, '_product_image_gallery', true))), 'download_limit' => get_post_meta($id, '_download_limit', true), 'download_expiry' => get_post_meta($id, '_download_expiry', true), 'image_id' => get_post_thumbnail_id($id))); // Gets extra data associated with the product. // Like button text or product URL for external products. foreach ($product->get_extra_data_keys() as $key) { $function = 'set_' . $key; if (is_callable(array($product, $function))) { $product->{$function}(get_post_meta($product->get_id(), '_' . $key, true)); } } }
/** * 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; }
/** * Sync product rating count. Can be called statically. * * @deprecated 2.7.0 * @param int $post_id */ public static function sync_rating_count($post_id) { wc_deprecated_function('WC_Product::sync_rating_count', '2.7', 'WC_Comments::get_rating_counts_for_product or leave to CRUD.'); $counts = WC_Comments::get_rating_counts_for_product(wc_get_product($post_id)); update_post_meta($post_id, '_wc_rating_count', $counts); }