function product_custom_loop(){ ob_start(); $args = array( 'post_type' => ' product', 'posts_per_page' => 6, ); $results = new WP_Query($args); // echo '<pre>'; // var_dump($atts['category']); ?> <section id="home"> <div class="container-fluid"> <div class="row ser-content product-slider"> <?php if($results->have_posts()): while($results->have_posts()): $results->the_post(); global $product; // $categories = get_the_terms(get_the_ID(), 'product_cat'); ?> <div class="col-md-4"> <div class="product_col"> <div class="product_inner"> <div class="product_top"> <a class="prCart" href="<?php echo esc_url( get_site_url() . '/cart/?add-to-cart=' . $product->get_id() ); ?>"><span class="list-icon wd-icon fas fa-shopping-bag"></span></a> <div class="price_product"> <?php if ($product->is_type( 'simple' )) { ?> <?php echo $product->get_price_html(); ?> <?php } ?> <?php if($product->get_type()=='variable') { $available_variations = $product->get_available_variations(); $variation_id=$available_variations[0]['variation_id']; $variable_product1= new WC_Product_Variation( $variation_id ); $regular_price = $variable_product1 ->regular_price; $sales_price = $variable_product1 -> sale_price; if (empty($sales_price)) { $sales_price = 0; } } ?> </div> </div> <div class="product_img"> <?php the_post_thumbnail('full'); ?> </div> <div class="product_title"> <h4><?php echo esc_html(get_the_title()); ?></h4> </div> </div> </div> </div> <?php endwhile; endif; ?> </div> </div> </section> <?php wp_reset_postdata(); return ob_get_clean(); } add_shortcode('wp-product','product_custom_loop');
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter