Using plugins MultivendorX + Woocommerce, I’m trying to get a random list of vendors (avatar, name, rating).
The problem with getting a vendor avatar is that the line of code
$image = $vendor->get_image() ? $vendor->get_image('image', array(125, 125)) : $MVX->plugin_url . 'assets/images/WP-stdavatar.png';
breaks any page where the shortcode [random_vendors]
is displayed.
The code I’m using:
function random_vendors_shortcode() {
if ( is_tax( 'dc_vendor_shop' ) ) {
$current_taxonomy = get_queried_object();
$taxonomies = get_terms(array(
'taxonomy' => 'dc_vendor_shop',
'number' => 10,
'orderby' => 'rand',
));
$output = '<ul class="container random-vendors">';
foreach ($taxonomies as $taxonomy) {
if ($taxonomy->term_id == $current_taxonomy->term_id) {
continue;
}
$vendor = get_mvx_vendor($taxonomy->term_id);
$image = $vendor->get_image() ? $vendor->get_image('image', array(125, 125)) : $MVX->plugin_url . 'assets/images/WP-stdavatar.png';
$rating_info = mvx_get_vendor_review_info($taxonomy->term_id);
$rating = round($rating_info['avg_rating'], 2);
$review_count = isset($rating_info['total_rating']) ? intval($rating_info['total_rating']) : 0;
$output .= '<li>';
$output .= '<div class="random-vendor">';
$output .= '<a href="' . get_term_link($taxonomy) . '">' . $taxonomy->name . '</a>';
$output .= '<div class="vendor-image">';
$output .= '<img src="'. $image .'" alt="'. $taxonomy->name .'">';
$output .= '</div>';
$output .= '<div class="mvx_vendor_rating">';
if ($rating > 0) {
$output .= '<div class="star-rating"><span style="width:'.(($rating / 5) * 100).'%"><strong itemprop="ratingValue" class="ratingvp">'.$rating.'</strong> из 5 </span></div>';
} else {
$output .= '<div itemprop="ratingValue" class="star-rating"></div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
}
add_shortcode('random_vendors', 'random_vendors_shortcode');
Any help please