本文整理汇总了PHP中WC_Product::get_rating_count方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_rating_count方法的具体用法?PHP WC_Product::get_rating_count怎么用?PHP WC_Product::get_rating_count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::get_rating_count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_product_data
/**
* Get standard product data that applies to every product type
*
* @since 2.1
* @param WC_Product $product
* @return array
*/
private function get_product_data($product)
{
return array('title' => $product->get_name(), 'id' => $product->get_id(), 'created_at' => $this->server->format_datetime($product->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($product->get_date_modified(), false, true), 'type' => $product->get_type(), 'status' => $product->get_status(), 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => wc_format_decimal($product->get_price(), 2), 'regular_price' => wc_format_decimal($product->get_regular_price(), 2), 'sale_price' => $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->get_catalog_visibility(), 'on_sale' => $product->is_on_sale(), 'weight' => $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : null, 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height(), 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => apply_filters('the_content', $product->get_description()), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'categories' => wc_get_object_terms($product->get_id(), 'product_cat', 'name'), 'tags' => wc_get_object_terms($product->get_id(), 'product_tag', 'name'), 'images' => $this->get_images($product), 'featured_src' => wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'purchase_note' => apply_filters('the_content', $product->get_purchase_note()), 'total_sales' => $product->get_total_sales(), 'variations' => array(), 'parent' => array());
}
示例2: vc_gitem_template_attribute_woocommerce_product
/**
* Gte woocommerce data for product
*
* @param $value
* @param $data
*
* @return string
*/
function vc_gitem_template_attribute_woocommerce_product($value, $data)
{
$label = '';
/**
* @var null|Wp_Post $post ;
* @var string $data ;
*/
extract(array_merge(array('post' => null, 'data' => ''), $data));
require_once WC()->plugin_path() . '/includes/abstracts/abstract-wc-product.php';
$product = new WC_Product($post);
if (preg_match('/_labeled$/', $data)) {
$data = preg_replace('/_labeled$/', '', $data);
$label = apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_label', Vc_Vendor_Woocommerce::getProductFieldLabel($data) . ': ');
}
$price_format = get_woocommerce_price_format();
switch ($data) {
case 'id':
$value = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id;
break;
case 'sku':
$value = $product->get_sku();
break;
case 'price':
$value = sprintf($price_format, wc_format_decimal($product->get_price(), 2), get_woocommerce_currency());
break;
case 'regular_price':
$value = sprintf($price_format, wc_format_decimal($product->get_regular_price(), 2), get_woocommerce_currency());
break;
case 'sale_price':
$value = sprintf(get_woocommerce_price_format(), $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : '', get_woocommerce_currency());
break;
case 'price_html':
$value = $product->get_price_html();
break;
case 'reviews_count':
$value = count(get_comments(array('post_id' => $post->ID, 'approve' => 'approve')));
break;
case 'short_description':
$value = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt);
break;
case 'dimensions':
$units = get_option('woocommerce_dimension_unit');
$value = $product->length . $units . 'x' . $product->width . $units . 'x' . $product->height . $units;
break;
case 'raiting_count':
$value = $product->get_rating_count();
break;
case 'weight':
$value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : '';
break;
case 'on_sale':
$value = $product->is_on_sale() ? 'yes' : 'no';
// @todo change
break;
default:
$value = $product->{$data};
}
return strlen($value) > 0 ? $label . apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_value', $value) : '';
}
示例3: get_product_data
/**
* Get standard product data that applies to every product type
*
* @since 2.1
* @param WC_Product $product
* @return WC_Product
*/
private function get_product_data($product)
{
return array('title' => $product->get_title(), 'id' => (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id, 'created_at' => $this->server->format_datetime($product->get_post_data()->post_date_gmt), 'updated_at' => $this->server->format_datetime($product->get_post_data()->post_modified_gmt), 'type' => $product->product_type, 'status' => $product->get_post_data()->post_status, 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => $product->get_price(), 'regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->visibility, 'on_sale' => $product->is_on_sale(), 'product_url' => $product->is_type('external') ? $product->get_product_url() : '', 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', 'weight' => $product->get_weight() ? $product->get_weight() : null, 'dimensions' => array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => wpautop(do_shortcode($product->get_post_data()->post_content)), 'short_description' => apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt), 'reviews_allowed' => 'open' === $product->get_post_data()->comment_status, 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => (int) $product->get_rating_count(), 'related_ids' => array_map('absint', array_values($product->get_related())), 'upsell_ids' => array_map('absint', $product->get_upsells()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sells()), 'parent_id' => $product->post->post_parent, 'categories' => wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')), 'tags' => wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')), 'images' => $this->get_images($product), 'featured_src' => (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id)), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => (int) $product->download_limit, 'download_expiry' => (int) $product->download_expiry, 'download_type' => $product->download_type, 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->purchase_note))), 'total_sales' => metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0, 'variations' => array(), 'parent' => array(), 'grouped_products' => array());
}
示例4: get_product_data
//.........这里部分代码省略.........
$product_data['on_sale'] = $product->is_on_sale();
}
if (!$fields || $fields && in_array('product_url', $field_list)) {
$product_data['product_url'] = $product->is_type('external') ? $product->get_product_url() : '';
}
if (!$fields || $fields && in_array('button_text', $field_list)) {
$product_data['button_text'] = $product->is_type('external') ? $product->get_button_text() : '';
}
if (!$fields || $fields && in_array('weight', $field_list)) {
$product_data['weight'] = $product->get_weight() ? $product->get_weight() : null;
}
if (!$fields || $fields && in_array('dimensions', $field_list)) {
$product_data['dimensions'] = array('length' => $product->length, 'width' => $product->width, 'height' => $product->height, 'unit' => get_option('woocommerce_dimension_unit'));
}
if (!$fields || $fields && in_array('shipping_required', $field_list)) {
$product_data['shipping_required'] = $product->needs_shipping();
}
if (!$fields || $fields && in_array('shipping_taxable', $field_list)) {
$product_data['shipping_taxable'] = $product->is_shipping_taxable();
}
if (!$fields || $fields && in_array('shipping_class', $field_list)) {
$product_data['shipping_class'] = $product->get_shipping_class();
}
if (!$fields || $fields && in_array('shipping_class_id', $field_list)) {
$product_data['shipping_class_id'] = 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null;
}
if (!$fields || $fields && in_array('description', $field_list)) {
$product_data['description'] = wpautop(do_shortcode($product->get_post_data()->post_content));
}
if (!$fields || $fields && in_array('short_description', $field_list)) {
$product_data['short_description'] = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt);
}
if (!$fields || $fields && in_array('reviews_allowed', $field_list)) {
$product_data['reviews_allowed'] = 'open' === $product->get_post_data()->comment_status;
}
if (!$fields || $fields && in_array('average_rating', $field_list)) {
$product_data['average_rating'] = wc_format_decimal($product->get_average_rating(), 2);
}
if (!$fields || $fields && in_array('rating_count', $field_list)) {
$product_data['rating_count'] = (int) $product->get_rating_count();
}
if (!$fields || $fields && in_array('related_ids', $field_list)) {
$product_data['related_ids'] = array_map('absint', array_values($product->get_related()));
}
if (!$fields || $fields && in_array('upsell_ids', $field_list)) {
$product_data['upsell_ids'] = array_map('absint', $product->get_upsells());
}
if (!$fields || $fields && in_array('cross_sell_ids', $field_list)) {
$product_data['cross_sell_ids'] = array_map('absint', $product->get_cross_sells());
}
if (!$fields || $fields && in_array('parent_id', $field_list)) {
$product_data['parent_id'] = $product->post->post_parent;
}
if (!$fields || $fields && in_array('categories', $field_list)) {
$product_data['categories'] = wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names'));
}
if (!$fields || $fields && in_array('tags', $field_list)) {
$product_data['tags'] = wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names'));
}
if (!$fields || $fields && in_array('images', $field_list)) {
$product_data['images'] = $this->get_images($product);
}
if (!$fields || $fields && in_array('featured_src', $field_list)) {
$product_data['featured_src'] = (string) wp_get_attachment_url(get_post_thumbnail_id($product->is_type('variation') ? $product->variation_id : $product->id));
}
if (!$fields || $fields && in_array('attributes', $field_list)) {
$product_data['attributes'] = $this->get_attributes($product);
}
if (!$fields || $fields && in_array('downloads', $field_list)) {
$product_data['downloads'] = $this->get_downloads($product);
}
if (!$fields || $fields && in_array('download_limit', $field_list)) {
$product_data['download_limit'] = (int) $product->download_limit;
}
if (!$fields || $fields && in_array('download_expiry', $field_list)) {
$product_data['download_expiry'] = (int) $product->download_expiry;
}
if (!$fields || $fields && in_array('download_type', $field_list)) {
$product_data['download_type'] = $product->download_type;
}
if (!$fields || $fields && in_array('purchase_note', $field_list)) {
$product_data['purchase_note'] = wpautop(do_shortcode(wp_kses_post($product->purchase_note)));
}
if (!$fields || $fields && in_array('total_sales', $field_list)) {
$product_data['total_sales'] = metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0;
}
if (!$fields || $fields && in_array('variations', $field_list)) {
$product_data['variations'] = array();
}
if (!$fields || $fields && in_array('parent', $field_list)) {
$product_data['parent'] = array();
}
if (!$fields || $fields && in_array('grouped_products', $field_list)) {
$product_data['grouped_products'] = array();
}
if (!$fields || $fields && in_array('menu_order', $field_list)) {
$product_data['menu_order'] = $product->post->menu_order;
}
return $product_data;
}
示例5: get_average_rating_for_product
/**
* Get product rating for a product. Please note this is not cached.
*
* @since 2.7.0
* @param WC_Product $product
* @return float
*/
public static function get_average_rating_for_product(&$product)
{
global $wpdb;
$count = $product->get_rating_count();
if ($count) {
$ratings = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT SUM(meta_value) FROM {$wpdb->commentmeta}\n\t\t\t\tLEFT JOIN {$wpdb->comments} ON {$wpdb->commentmeta}.comment_id = {$wpdb->comments}.comment_ID\n\t\t\t\tWHERE meta_key = 'rating'\n\t\t\t\tAND comment_post_ID = %d\n\t\t\t\tAND comment_approved = '1'\n\t\t\t\tAND meta_value > 0\n\t\t\t", $product->get_id()));
$average = number_format($ratings / $count, 2, '.', '');
} else {
$average = 0;
}
$product->set_average_rating($average);
$data_store = $product->get_data_store();
$data_store->update_average_rating($product);
return $average;
}