Topic: How to make a woocommerce product category page according to MDB WP tutorial?
ecosse free asked 5 years ago
Hello, I'm trying to do a custom woocommerce product category page according to MDB Wordpress tutorial → https://mdbootstrap.com/education/wordpress/woocommerce-5-product-listing-page/
There's code to add to woocommerce.php. Do you know which file in woocommerce is corresponding to product category page? Is that content-product_cat.php?
Just editing category page may be simple but how to make a loop just for products from specify category?
I found some code on google but idk to which file should I add that:
<ul class="products">
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'shoes', 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<h2>Shoes</h2>
<li class="product">
<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); ?>">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?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="300px" height="300px" />'; ?>
<h3><?php the_title(); ?></h3>
<span class="price"><?php echo $product->get_price_html(); ?></span>
</a>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul><!--/.products-->
I hope someone can help me here with that, thanks in advance.
Arkadiusz Cacko staff answered 5 years ago
Hi @ecosse
To edit product category page, you have to create a copy of the archive-product.php
file from the plugins > woocommerce > templates
and paste it to your theme directory.
Regards
Arek
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.7.4
- Device: PC
- Browser: Chrome
- OS: Manjaro Linux
- Provided sample code: No
- Provided link: Yes