本文整理汇总了PHP中WC_Product::get_average_rating方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_average_rating方法的具体用法?PHP WC_Product::get_average_rating怎么用?PHP WC_Product::get_average_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::get_average_rating方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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());
}
示例3: array
//.........这里部分代码省略.........
if ($key == $sort_order) {
echo '<div>' . __("Initial Order", "ts_visual_composer_extend") . ': ' . $value . '</div>';
}
}
echo '<div>' . __("Show Filter Button", "ts_visual_composer_extend") . ': ' . $filter_menu . '</div>';
echo '<div>' . __("Show Layout Button", "ts_visual_composer_extend") . ': ' . $layout_menu . '</div>';
echo '<div>' . __("Show Sort Criterion Button", "ts_visual_composer_extend") . ': ' . $sort_menu . '</div>';
echo '<div>' . __("Show Directions Buttons", "ts_visual_composer_extend") . ': ' . $directions_menu . '</div>';
echo '</div>';
} else {
$opening .= '<div id="' . $posts_container_id . '" class="ts-isotope-posts-grid-parent ' . ($layout == 'spineTimeline' ? 'ts-timeline ' : 'ts-postsgrid ') . 'ts-timeline-' . $sort_order . ' ts-posts-timeline ' . $isotope_posts_list_class . ' ' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . ';" data-lazy="' . $posts_lazy . '" data-count="' . $posts_limit . '" data-ajax="' . $posts_ajax . '" data-trigger="' . $posts_trigger . '" data-column="' . $column_width . '" data-layout="' . $layout . '" data-sort="' . $sort_by . '" data-order="' . $sort_order . '" data-break="' . $layout_break . '" data-type="' . $post_type . '">';
// Create Individual Post Output
$postCounter = 0;
$postCategories = array();
$categoriesCount = 0;
if (post_type_exists($post_type) && $loop->have_posts()) {
$products .= '<div class="ts-timeline-content">';
$products .= '<ul id="ts-isotope-posts-grid-' . $postsgrid_random . '" class="ts-isotope-posts-grid ts-timeline-list" data-layout="' . $layout . '" data-key="' . $postsgrid_random . '">';
while ($loop->have_posts()) {
$loop->the_post();
$postCounter++;
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
$rating_class = 'ts-rating-stars-heart1';
} else {
if ($rating_icon == "ts-ecommerce-heart") {
$rating_class = 'ts-rating-stars-heart2';
示例4: update_average_rating
/**
* Update a products average rating meta.
*
* @since 2.7.0
* @param WC_Product $product
*/
public function update_average_rating($product)
{
update_post_meta($product->get_id(), '_wc_average_rating', $product->get_average_rating('edit'));
}
示例5: extract
//.........这里部分代码省略.........
$output .= '<div id="ts-owlslider-progressbar-' . $woo_random . '" class="ts-owlslider-progressbar-holder" style=""><div class="ts-owlslider-progressbar" style="background: ' . $bar_color . '; height: 100%; width: 0%;"></div></div>';
}
// Add Navigation Controls
if ($frontend_edit == "false") {
$output .= '<div id="ts-owlslider-controls-' . $woo_random . '" class="ts-owlslider-controls" style="' . ($auto_play == "true" || $show_navigation == "true" ? "display: block;" : "display: none;") . '">';
$output .= '<div id="ts-owlslider-controls-next-' . $woo_random . '" style="' . ($show_navigation == "true" ? "display: block;" : "display: none;") . '" class="ts-owlslider-controls-next"><span class="ts-ecommerce-arrowright5"></span></div>';
$output .= '<div id="ts-owlslider-controls-prev-' . $woo_random . '" style="' . ($show_navigation == "true" ? "display: block;" : "display: none;") . '" class="ts-owlslider-controls-prev"><span class="ts-ecommerce-arrowleft5"></span></div>';
if ($auto_play == "true") {
$output .= '<div id="ts-owlslider-controls-play-' . $woo_random . '" class="ts-owlslider-controls-play active"><span class="ts-ecommerce-pause"></span></div>';
}
$output .= '</div>';
}
// Front-Edit Message
if ($frontend_edit == "true") {
$output .= $slider_message;
}
// Add Slider
$output .= '<div id="' . $woo_slider_id . '" class="' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . 'px;" data-id="' . $woo_random . '" data-items="' . $products_slide . '" data-breakpointscustom="' . $breakpoints_custom . '" data-breakpointitems="' . $breakpoints_items . '" data-rtl="' . $page_rtl . '" data-loop="' . $items_loop . '" data-navigation="' . $show_navigation . '" data-dots="' . $show_dots . '" data-mobile="' . $animation_mobile . '" data-animationin="' . $animation_in . '" data-animationout="' . $animation_out . '" data-height="' . $auto_height . '" data-play="' . $auto_play . '" data-bar="' . $show_bar . '" data-color="' . $bar_color . '" data-speed="' . $show_speed . '" data-hover="' . $stop_hover . '">';
if ($loop->have_posts()) {
while ($loop->have_posts()) {
$loop->the_post();
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
$rating_class = 'ts-rating-stars-heart1';
} else {
if ($rating_icon == "ts-ecommerce-heart") {
$rating_class = 'ts-rating-stars-heart2';
示例6: 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;
}
示例7: shop_isle_products_slider_on_single_page
/**
* Products slider on single page product
* @since 1.0.0
*/
function shop_isle_products_slider_on_single_page()
{
global $wp_customize;
$shop_isle_products_slider_single_hide = get_theme_mod('shop_isle_products_slider_single_hide');
if (isset($shop_isle_products_slider_single_hide) && $shop_isle_products_slider_single_hide != 1) {
echo '<hr class="divider-w">';
echo '<section class="module module-small-bottom aya">';
} elseif (isset($wp_customize)) {
echo '<hr class="divider-w">';
echo '<section class="module module-small-bottom shop_isle_hidden_if_not_customizer">';
}
if (isset($shop_isle_products_slider_single_hide) && $shop_isle_products_slider_single_hide != 1 || isset($wp_customize)) {
echo '<div class="container">';
$shop_isle_products_slider_title = get_theme_mod('shop_isle_products_slider_title', __('Exclusive products', 'shop-isle'));
$shop_isle_products_slider_subtitle = get_theme_mod('shop_isle_products_slider_subtitle', __('Special category of products', 'shop-isle'));
if (!empty($shop_isle_products_slider_title) || !empty($shop_isle_products_slider_subtitle)) {
echo '<div class="row">';
echo '<div class="col-sm-6 col-sm-offset-3">';
if (!empty($shop_isle_products_slider_title)) {
echo '<h2 class="module-title font-alt">' . $shop_isle_products_slider_title . '</h2>';
}
if (!empty($shop_isle_products_slider_subtitle)) {
echo '<div class="module-subtitle font-serif">' . $shop_isle_products_slider_subtitle . '</div>';
}
echo '</div>';
echo '</div><!-- .row -->';
}
$shop_isle_products_slider_category = get_theme_mod('shop_isle_products_slider_category');
if (!empty($shop_isle_products_slider_category) && $shop_isle_products_slider_category != '-') {
$shop_isle_products_slider_args = array('post_type' => 'product', 'posts_per_page' => 10, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $shop_isle_products_slider_category)));
$shop_isle_products_slider_loop = new WP_Query($shop_isle_products_slider_args);
if ($shop_isle_products_slider_loop->have_posts()) {
echo '<div class="row">';
echo '<div class="owl-carousel text-center" data-items="5" data-pagination="false" data-navigation="false">';
while ($shop_isle_products_slider_loop->have_posts()) {
$shop_isle_products_slider_loop->the_post();
echo '<div class="owl-item">';
echo '<div class="col-sm-12">';
echo '<div class="ex-product">';
echo '<a href="' . get_permalink() . '">' . woocommerce_get_product_thumbnail() . '</a>';
echo '<h4 class="shop-item-title font-alt"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h4>';
$product = new WC_Product(get_the_ID());
$rating_html = $product->get_rating_html($product->get_average_rating());
if ($rating_html && get_option('woocommerce_enable_review_rating') === 'yes') {
echo '<div class="product-rating-home">' . $rating_html . '</div>';
}
if (!empty($product)) {
if (function_exists('get_woocommerce_price_format')) {
$format_string = get_woocommerce_price_format();
}
if (!empty($format_string)) {
switch ($format_string) {
case '%1$s%2$s':
echo get_woocommerce_currency_symbol() . $product->price;
break;
case '%2$s%1$s':
echo $product->price . get_woocommerce_currency_symbol();
break;
case '%1$s %2$s':
echo get_woocommerce_currency_symbol() . ' ' . $product->price;
break;
case '%2$s %1$s':
echo $product->price . ' ' . get_woocommerce_currency_symbol();
break;
}
} else {
echo get_woocommerce_currency_symbol() . $product->price;
}
}
echo '</div>';
echo '</div>';
echo '</div>';
}
wp_reset_postdata();
echo '</div>';
echo '</div>';
}
} else {
$shop_isle_products_slider_args = array('post_type' => 'product', 'posts_per_page' => 10);
$shop_isle_products_slider_loop = new WP_Query($shop_isle_products_slider_args);
if ($shop_isle_products_slider_loop->have_posts()) {
echo '<div class="row">';
echo '<div class="owl-carousel text-center" data-items="5" data-pagination="false" data-navigation="false">';
while ($shop_isle_products_slider_loop->have_posts()) {
$shop_isle_products_slider_loop->the_post();
echo '<div class="owl-item">';
echo '<div class="col-sm-12">';
echo '<div class="ex-product">';
echo '<a href="' . get_permalink() . '">' . woocommerce_get_product_thumbnail() . '</a>';
echo '<h4 class="shop-item-title font-alt"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h4>';
$product = new WC_Product(get_the_ID());
$rating_html = $product->get_rating_html($product->get_average_rating());
if ($rating_html && get_option('woocommerce_enable_review_rating') === 'yes') {
echo '<div class="product-rating-home">' . $rating_html . '</div>';
}
if (!empty($product)) {
//.........这里部分代码省略.........
示例8: extract
//.........这里部分代码省略.........
// Add Navigation Controls
$output .= '<div id="ts-newsticker-controls-' . $woo_random . '" class="ts-newsticker-controls" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . ' ' . $newsticker_controls . '">';
$output .= '<div id="ts-newsticker-controls-next-' . $woo_random . '" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . '" class="ts-newsticker-controls-next"><span class="ts-ecommerce-arrowright5"></span></div>';
$output .= '<div id="ts-newsticker-controls-prev-' . $woo_random . '" style="' . ($ticker_controls == "true" ? "display: block;" : "display: none;") . '" class="ts-newsticker-controls-prev"><span class="ts-ecommerce-arrowleft5"></span></div>';
$output .= '<div id="ts-newsticker-controls-stop-' . $woo_random . '" class="ts-newsticker-controls-play" style="' . ($ticker_auto == "true" ? "display: block;" : "display: none;") . '"><span class="ts-ecommerce-pause"></span></div>';
$output .= '<div id="ts-newsticker-controls-play-' . $woo_random . '" class="ts-newsticker-controls-play" style="' . ($ticker_auto == "true" ? "display: none;" : "display: block;") . '"><span class="ts-ecommerce-play"></span></div>';
$output .= '</div>';
if ($ticker_side == "left" && $ticker_title == "true") {
$output .= '<div id="ts-newsticker-header-' . $woo_random . '" class="header ' . $ticker_border_radius . '" style="background: ' . $ticker_background . '; color: ' . $ticker_color . '; left: 0;">';
if ($ticker_icon != '' && $ticker_icon != 'transparent' && $ticker_symbol == "true") {
$output .= '<i class="ts-font-icon ' . $ticker_icon . '" style="color: ' . $ticker_paint . '"></i>';
}
$output .= '<span>' . $ticker_header . '</span>';
$output .= '</div>';
}
$output .= '<ul id="ts-newsticker-ticker-' . $woo_random . '" class="newsticker ' . $ticker_border_radius . '" style="' . $newsticker_header . '">';
while ($loop->have_posts()) {
$loop->the_post();
$postCounter++;
if ($postCounter < $posts_limit + 1) {
$postAttributes = 'data-full="' . get_post_time($date_format) . '" data-time="' . get_post_time($time_format) . '" data-author="' . get_the_author() . '" data-date="' . get_post_time('U') . '" data-modified="' . get_the_modified_time('U') . '" data-title="' . get_the_title() . '" data-comments="' . get_comments_number() . '" data-id="' . get_the_ID() . '"';
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
$rating_class = 'ts-rating-stars-heart1';
} else {
if ($rating_icon == "ts-ecommerce-heart") {
$rating_class = 'ts-rating-stars-heart2';
示例9: extract
function TS_VCSC_WooCommerce_Rating_Basic_Function($atts, $content = null)
{
global $VISUAL_COMPOSER_EXTENSIONS;
global $product;
global $woocommerce;
ob_start();
if ($VISUAL_COMPOSER_EXTENSIONS->TS_VCSC_LoadFrontEndForcable == "false") {
wp_enqueue_style('ts-extend-simptip');
wp_enqueue_style('ts-font-ecommerce');
wp_enqueue_style('ts-visual-composer-extend-front');
wp_enqueue_script('ts-visual-composer-extend-front');
}
extract(shortcode_atts(array('best_rated' => 'false', 'id' => '', 'rating_maximum' => 5, 'rating_size' => 24, 'rating_quarter' => 'true', 'rating_title' => 'true', 'rating_auto' => 'true', 'rating_position' => 'top', 'rating_rtl' => 'false', 'rating_symbol' => 'other', 'rating_icon' => '', 'color_rated' => '#FFD800', 'color_empty' => '#e3e3e3', 'caption_show' => 'true', 'caption_position' => 'left', 'caption_digits' => '.', 'caption_danger' => '#d9534f', 'caption_warning' => '#f0ad4e', 'caption_info' => '#5bc0de', 'caption_primary' => '#428bca', 'caption_success' => '#5cb85c', 'title_size' => 24, 'title_truncate' => 'true', 'use_name' => 'true', 'custom_title' => '', 'show_cart' => 'true', 'cart_color' => '#cccccc', 'show_link' => 'true', 'link_color' => '#cccccc', 'tooltip_css' => 'false', 'tooltip_content' => '', 'tooltip_position' => 'ts-simptip-position-top', 'tooltip_style' => '', 'margin_top' => 20, 'margin_bottom' => 20, 'el_id' => '', 'el_class' => '', 'css' => ''), $atts));
// Final Query Arguments
add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses'));
$meta_query = WC()->query->get_meta_query();
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'desc', 'paged' => 1, 'meta_query' => $meta_query);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
$best_rating = 0;
while ($loop->have_posts()) {
$loop->the_post();
$product_id = get_the_ID();
$product = new WC_Product($product_id);
if ($product_id == $id) {
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
$link = get_permalink();
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
break;
}
}
}
wp_reset_postdata();
wp_reset_query();
if ($rating_title == "true") {
if ($use_name == "true") {
$rating_title = $product_title;
} else {
$rating_title = $custom_title;
}
} else {
$rating_title = '';
}
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
$rating_class = 'ts-rating-stars-star4';
} else {
if ($rating_icon == "ts-ecommerce-heartfull") {
$rating_class = 'ts-rating-stars-heart1';
} else {
if ($rating_icon == "ts-ecommerce-heart") {
$rating_class = 'ts-rating-stars-heart2';
} else {
if ($rating_icon == "ts-ecommerce-thumbsup") {
$rating_class = 'ts-rating-stars-thumb';
} else {
if ($rating_icon == "ts-ecommerce-ribbon4") {
$rating_class = 'ts-rating-stars-ribbon';
}
}
}
}
}
}
}
}
} else {
//.........这里部分代码省略.........