Advertisement
arnabkumar

woocommerce product query

Dec 1st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <ul class="products">
  2.     <?php
  3.         global $post;
  4.         // Setup your custom query
  5.              $args = array('posts_per_page' => 4,'post_type' => 'product',
  6.             //add category
  7.             'tax_query' => array(
  8.             'relation' => 'AND',
  9.         array(
  10.             'taxonomy' => 'product_cat',
  11.             'field' => 'slug',
  12.             'terms' => 'html' //example : ‘term’ => ‘red-shoes’, ‘books’, ‘fiction-books’.
  13.         )
  14.          ),
  15.              'orderby' => 'title',
  16.              );
  17.         $myposts = get_posts( $args );
  18.         foreach( $myposts as $post ) : setup_postdata($post); ?>
  19.        
  20.        
  21.          <li class="col-sm-4">
  22.          <div class="shop_product_inner">  <!-- shop_single here woocommerce img id you can ise usr won crop id  -->
  23.                     <a href="<?php the_permalink() ?>">
  24.                         <?php if ( has_post_thumbnail( get_the_ID() ) ) {
  25.                              the_post_thumbnail('shop_single', array('class' => 'img-responsive project-image'));
  26.                         } else {
  27.                   echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" />';
  28.                         } ?>
  29.                         <div class="shop_product_inner_caption">
  30.                             <h2><?php the_title(); ?></h2>
  31.      
  32.                             <p><?php echo $product->get_price_html(); ?></p>
  33.                             <?php woocommerce_template_loop_add_to_cart(); //ouptput the woocommerce loop add to cart button ?>
  34.                         </div>
  35.                     </a>
  36.                 </div>
  37.  
  38.         </li>
  39.        
  40.         <?php endforeach; ?>
  41.     </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement