To display the product category description above the products list in WooCommerce, you can customize your theme's template files. Here's how you can do it:
Step 1: Locate the Correct Template File
-
Go to your WordPress dashboard.
-
Navigate to Appearance > Theme File Editor (or use an FTP client to access your theme files).
-
Locate the
archive-product.phpfile in your theme. This file controls the display of product category pages.-
If your theme doesn't have this file, WooCommerce will use the default template from the
woocommerceplugin folder. You can copy the defaultarchive-product.phpfile fromwp-content/plugins/woocommerce/templates/to your theme'swoocommercefolder (e.g.,wp-content/themes/your-theme/woocommerce/).
-
Step 2: Add the Category Description
-
Open the
archive-product.phpfile. -
Find the place where you want to display the category description. Typically, this is above the product loop.
-
Add the following code to display the category description:
<?php
if (is_product_category()) {
$term = get_queried_object();
if ($term && !empty($term->description)) {
echo '<div class="category-description">' . wpautop($term->description) . '</div>';
}
}
?>
This code checks if the current page is a product category archive and retrieves the category description using get_queried_object().
Step 3: Style the Description (Optional)
You can add custom CSS to style the category description. For example:
.category-description {
margin-bottom: 20px;
font-size: 16px;
line-height: 1.6;
color: #333;
}
Add this CSS to your theme's style.css file or via Appearance > Customize > Additional CSS.
Step 4: Test Your Changes
-
Visit a product category page on your site to ensure the description appears above the products list.
-
If the description doesn't show up, double-check that the category has a description entered in the WordPress admin (go to Products > Categories and edit the category).
1451

被折叠的 条评论
为什么被折叠?



