Add Admin Side Option Select Multiple Product Using ACF Post Object Field [Select Product Id in ACF Field] (Best Seller Slider Shortcode)
/* Best Seller Slider */
function our_best_seller_slider()
{
ob_start();
if(is_single()){
$product_ids = get_field('select_interesting_product');
if(empty($product_ids)) return;
}else{
$product_ids = get_field('select_our_bestsellers_product', 'option');
if(empty($product_ids)) return;
}
/*$dataobituary_query = new WP_Query(array(
'post_type' => 'product',
'posts_per_page' => -1,
'order' => 'DESC',
'post__in' => $product_ids
)); */
$args = array(
'status' => 'publish',
'include' => $product_ids,
);
$products = wc_get_products( $args );
?>
<div class="our-bestseller-slider">
<div class="owl-carousel our-best-seller-slider">
<?php
// Loop through the obituaries:
foreach ( $products as $product ){
$pro_id = $product->get_id();
$img = $product->get_image();
$product_link = get_permalink($pro_id);
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average = $product->get_average_rating();
?>
<div class="item">
<div class="seller-slider-box">
<div class="seller-img">
<a href="<?php echo $product_link; ?>">
<?php echo $img; ?>
</a>
</div>
<div class="seller-pro-star-rating">
<?php
//echo 'review_count = '.$review_count;
//echo ' = rating_count = '.$rating_count;
//echo ' = average = '.$average;
//echo wc_get_rating_html( $rating_count );
//echo do_shortcode('[yith_ywar_show_reviews product_id = '.$pro_id.']');
//echo wc_get_rating_html( $product->get_average_rating() );
//woocommerce_template_loop_rating() ;
// echo $product->get_rating_html();
if ( $rating_count > 0 ) :
?>
<div class="woocommerce woocommerce-product-rating">
<div class="star-rating">
<?php echo wc_get_star_rating_html( $average, $rating_count ) //echo $rating_html; ?>
</div>
</div>
<h4>
(<?php echo $review_count; ?> Bewertungen)
</h4>
<?php endif; ?>
</div>
<div class="seller-content">
<a href="<?php echo $product_link; ?>">
<h2><?php echo $product->get_name(); ?></h2>
</a>
<span class="pro-desc">
<?php echo $product->get_short_description(); ?>
</span>
</div>
<div class="seller-price">
<?php echo $product->get_price_html(); ?>
<p>
<?php echo get_field('price_per_liter',$pro_id); ?>
</p>
<h5 style="display: none; ">inkl. 19% MwSt. zzgl. Versandkosten</h5>
</div>
<div class="seller-btn">
<a href="<?php echo $product_link; ?>" class="btn-seller">Jetzt ausprobieren</a>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'our_best_seller_slider' , 'our_best_seller_slider' );
function our_best_seller_slider()
{
ob_start();
if(is_single()){
$product_ids = get_field('select_interesting_product');
if(empty($product_ids)) return;
}else{
$product_ids = get_field('select_our_bestsellers_product', 'option');
if(empty($product_ids)) return;
}
/*$dataobituary_query = new WP_Query(array(
'post_type' => 'product',
'posts_per_page' => -1,
'order' => 'DESC',
'post__in' => $product_ids
)); */
$args = array(
'status' => 'publish',
'include' => $product_ids,
);
$products = wc_get_products( $args );
?>
<div class="our-bestseller-slider">
<div class="owl-carousel our-best-seller-slider">
<?php
// Loop through the obituaries:
foreach ( $products as $product ){
$pro_id = $product->get_id();
$img = $product->get_image();
$product_link = get_permalink($pro_id);
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average = $product->get_average_rating();
?>
<div class="item">
<div class="seller-slider-box">
<div class="seller-img">
<a href="<?php echo $product_link; ?>">
<?php echo $img; ?>
</a>
</div>
<div class="seller-pro-star-rating">
<?php
//echo 'review_count = '.$review_count;
//echo ' = rating_count = '.$rating_count;
//echo ' = average = '.$average;
//echo wc_get_rating_html( $rating_count );
//echo do_shortcode('[yith_ywar_show_reviews product_id = '.$pro_id.']');
//echo wc_get_rating_html( $product->get_average_rating() );
//woocommerce_template_loop_rating() ;
// echo $product->get_rating_html();
if ( $rating_count > 0 ) :
?>
<div class="woocommerce woocommerce-product-rating">
<div class="star-rating">
<?php echo wc_get_star_rating_html( $average, $rating_count ) //echo $rating_html; ?>
</div>
</div>
<h4>
(<?php echo $review_count; ?> Bewertungen)
</h4>
<?php endif; ?>
</div>
<div class="seller-content">
<a href="<?php echo $product_link; ?>">
<h2><?php echo $product->get_name(); ?></h2>
</a>
<span class="pro-desc">
<?php echo $product->get_short_description(); ?>
</span>
</div>
<div class="seller-price">
<?php echo $product->get_price_html(); ?>
<p>
<?php echo get_field('price_per_liter',$pro_id); ?>
</p>
<h5 style="display: none; ">inkl. 19% MwSt. zzgl. Versandkosten</h5>
</div>
<div class="seller-btn">
<a href="<?php echo $product_link; ?>" class="btn-seller">Jetzt ausprobieren</a>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'our_best_seller_slider' , 'our_best_seller_slider' );