Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wc_category_title_archive_products(){
- $product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
- if ( $product_cats && ! is_wp_error ( $product_cats ) ){
- $single_cat = array_shift( $product_cats ); ?>
- <small class="product_category_title"><?php echo $single_cat->name; ?></small>
- <?php }
- }
- add_action( 'woocommerce_after_shop_loop_item', 'wc_category_title_archive_products', 5 );
- <?php
- $cat_args = array(
- 'parent' => '0',
- 'taxonomy' => 'product_cat'
- );
- $categories = get_categories( $cat_args );
- foreach ($categories as $category) { ?>
- <ul class="product-category">
- <?php
- $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'cat' => $category->cat_ID, 'orderby' => 'rand' );
- $loop = new WP_Query( $args );
- while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
- <!-- Your output -->
- <?php endwhile; ?>
- <?php wp_reset_query(); ?>
- </ul>
- }
- ?>
- <?php
- $cat_args = array(
- 'parent' => '0',
- 'taxonomy' => 'product_cat'
- );
- $categories = get_categories( $cat_args );
- foreach ($categories as $category) {
- echo $category->cat_name;
- echo do_shortcode('[product_category category="'.$category->cat_name.'" per_page="12" columns="4" orderby="date" order="DESC"]');
- }
- ?>
- function wpa89819_wc_single_product(){
- $product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
- if ( $product_cats && ! is_wp_error ( $product_cats ) ){
- $single_cat = array_shift( $product_cats ); ?>
- <h2 itemprop="name" class="product_category_title"><span><?php echo $single_cat->name; ?></span></h2>
- <?php }
- }
- add_action( 'woocommerce_after_shop_loop_item_title', 'wpa89819_wc_single_product', 5 );
Add Comment
Please, Sign In to add comment