Advertisement
Guest User

WooCommerce Custom Product Loop by Category

a guest
Jun 25th, 2012
2,846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <ul class="products">
  2.  
  3.                 <?php
  4.                     $args = array(
  5.         'post_type' => 'product',
  6.         'post_status' => 'publish',
  7.         'meta_query' => array(
  8.             array(
  9.                 'key' => '_visibility',
  10.                 'value' => array('catalog', 'visible'),
  11.                 'compare' => 'IN'
  12.             )
  13.         ),
  14.         'tax_query' => array(
  15.             array(
  16.                 'taxonomy' => 'product_cat',
  17.                 'terms' => 'permanent',
  18.                 'field' => 'slug',
  19.                 'operator' => 'IN'
  20.             )
  21.         )
  22.     );
  23.  
  24.                     $loop = new WP_Query( $args );
  25.                     while ( $loop->have_posts() ) : $loop->the_post(); global $product;
  26.        
  27.         if (!$product->is_visible()) continue;
  28.        
  29.         $woocommerce_loop['loop']++;?>
  30.            
  31.                 <li class="product">
  32.                
  33.                 <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
  34.                
  35.                     <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
  36.                    
  37.                     <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />'; ?>
  38.                                    
  39.                     <h3><?php the_title(); ?></h3>
  40.                                        
  41.                 </a>
  42.                
  43.                 <a href="<?php echo get_permalink($product->id); ?>" ><?php echo apply_filters('out_of_stock_add_to_cart_text', __('details', 'woocommerce')); ?></a> /
  44.                 <a href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" ><?php echo apply_filters('add_to_cart_text', __('Buy Now >>', 'woocommerce')); ?></a>
  45.                
  46.             </li>
  47.        
  48.             <?php endwhile; ?>
  49.             </ul><!--/.products-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement