Guest User

Untitled

a guest
Jan 23rd, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. function wc_category_title_archive_products(){
  2.  
  3. $product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
  4.  
  5. if ( $product_cats && ! is_wp_error ( $product_cats ) ){
  6.  
  7. $single_cat = array_shift( $product_cats ); ?>
  8.  
  9. <small class="product_category_title"><?php echo $single_cat->name; ?></small>
  10.  
  11. <?php }
  12. }
  13. add_action( 'woocommerce_after_shop_loop_item', 'wc_category_title_archive_products', 5 );
  14.  
  15. <?php
  16. $cat_args = array(
  17. 'parent' => '0',
  18. 'taxonomy' => 'product_cat'
  19. );
  20. $categories = get_categories( $cat_args );
  21.  
  22. foreach ($categories as $category) { ?>
  23. <ul class="product-category">
  24. <?php
  25. $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'cat' => $category->cat_ID, 'orderby' => 'rand' );
  26. $loop = new WP_Query( $args );
  27. while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
  28.  
  29. <!-- Your output -->
  30.  
  31. <?php endwhile; ?>
  32. <?php wp_reset_query(); ?>
  33. </ul>
  34. }
  35. ?>
  36.  
  37. <?php
  38. $cat_args = array(
  39. 'parent' => '0',
  40. 'taxonomy' => 'product_cat'
  41. );
  42. $categories = get_categories( $cat_args );
  43.  
  44. foreach ($categories as $category) {
  45. echo $category->cat_name;
  46. echo do_shortcode('[product_category category="'.$category->cat_name.'" per_page="12" columns="4" orderby="date" order="DESC"]');
  47. }
  48. ?>
  49.  
  50. function wpa89819_wc_single_product(){
  51.  
  52. $product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
  53.  
  54. if ( $product_cats && ! is_wp_error ( $product_cats ) ){
  55.  
  56. $single_cat = array_shift( $product_cats ); ?>
  57.  
  58. <h2 itemprop="name" class="product_category_title"><span><?php echo $single_cat->name; ?></span></h2>
  59.  
  60. <?php }
  61. }
  62. add_action( 'woocommerce_after_shop_loop_item_title', 'wpa89819_wc_single_product', 5 );
Add Comment
Please, Sign In to add comment