WordPress / 3 MIN READ
1. Understanding the Basics
Creating custom category page templates for WooCommerce is a fantastic way to make your store stand out! Let’s dive into a step-by-step tutorial to create
From the original Fervor library. Examples may use older package versions.
Creating custom category page templates for WooCommerce is a fantastic way to make your store stand out! Let’s dive into a step-by-step tutorial to create your own WooCommerce category page template. 🛠️
1. Understanding the Basics
WooCommerce uses WordPress templates to render pages. Category pages for WooCommerce are technically “product archives.” By creating a custom template, you can define how these pages look and function.
2. Setting Up Your Tools
Before starting, make sure you have:
- A child theme: Never edit the main theme directly; changes will be lost during updates.
- A code editor: Use tools like Visual Studio Code, Sublime Text, or even the built-in WordPress editor (not recommended for extensive edits).
- File access: Either through an FTP client like FileZilla or directly via your hosting panel.
3. Locate the Default Template
WooCommerce category pages use the archive-product.php template. Here’s how to find it:
- Navigate to your theme directory:
wp-content/themes/your-theme/. - Open the WooCommerce folder (if it exists) and locate
archive-product.php.
4. Copy the Template to Your Child Theme
- If you’re using a child theme (and you should), copy
archive-product.phpto the child theme folder.- Copy path:
wp-content/themes/your-theme/woocommerce/archive-product.php - Paste path:
wp-content/themes/your-child-theme/woocommerce/archive-product.php
- Copy path:
- If the WooCommerce folder doesn’t exist in your theme, copy the file from the WooCommerce plugin:
- WooCommerce plugin path:
wp-content/plugins/woocommerce/templates/archive-product.php.
- WooCommerce plugin path:
5. Customize the Template
Now, it’s time to unleash your creativity! Open the archive-product.php file and modify it.
Here are key areas to tweak:
-
Header Section: Replace or add custom headings or banners for category pages.
<?php if (is_product_category()) { $category = get_queried_object(); echo '<h1>' . $category->name . '</h1>'; echo '<p>' . $category->description . '</p>'; // Display category description } ?> -
Product Loop: WooCommerce uses a product loop to display products:
if (woocommerce_product_loop()) { woocommerce_product_loop_start(); while (have_posts()) { the_post(); wc_get_template_part('content', 'product'); // Load individual product template } woocommerce_product_loop_end(); } else { do_action('woocommerce_no_products_found'); }You can modify this loop to change how products appear, add extra data, or style the output.
-
Sidebar or Custom Filters: Add custom filters or sidebars with widgets to improve usability:
if (is_active_sidebar('custom-category-sidebar')) { dynamic_sidebar('custom-category-sidebar'); }
6. Conditional Templates
If you want different templates for specific categories:
- Duplicate
archive-product.phpand rename it. For example, createarchive-product-clothing.php. - Add this code to the top of the file:
<?php /** * Template Name: Clothing Category */ - Assign this template to a specific category using
is_product_category()infunctions.php:add_filter('template_include', 'custom_category_template'); function custom_category_template($template) { if (is_product_category('clothing')) { $new_template = locate_template('woocommerce/archive-product-clothing.php'); if ($new_template) return $new_template; } return $template; }
7. Styling the Template
To give your category pages a unique look, add custom CSS:
- Add styles in your child theme’s
style.cssfile. - Use specific category classes in the body tag. For example:
.product-category-clothing .woocommerce-products-header { background-color: #f2f2f2; color: #333; }
8. Test Your Work
- Visit a category page and refresh the browser to see your customizations.
- Test across multiple devices to ensure responsive design.
9. Enhance with Plugins (Optional)
If you prefer a no-code or low-code approach, try plugins like:
- Elementor Pro: Build category templates visually.
- WooCommerce Customizer: Add hooks and customizations.
- Advanced Custom Fields (ACF): Add custom fields to categories.
10. Deploy and Iterate
Once satisfied, back up your site and go live. Keep tweaking based on customer feedback or analytics.
Final Tip: Keep a Backup
Before making any changes, always create a backup of your site! Tools like UpdraftPlus or All-in-One WP Migration are lifesavers.
Happy customizing, and may your WooCommerce store shine like a diamond! 💎