Display WooCommerce Category Description Above Products

发布于:2025-02-10 ⋅ 阅读:(43) ⋅ 点赞:(0)

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

  1. Go to your WordPress dashboard.

  2. Navigate to Appearance > Theme File Editor (or use an FTP client to access your theme files).

  3. Locate the archive-product.php file 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 woocommerce plugin folder. You can copy the default archive-product.php file from wp-content/plugins/woocommerce/templates/ to your theme's woocommerce folder (e.g., wp-content/themes/your-theme/woocommerce/).


Step 2: Add the Category Description

  1. Open the archive-product.php file.

  2. Find the place where you want to display the category description. Typically, this is above the product loop.

  3. 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

  1. Visit a product category page on your site to ensure the description appears above the products list.

  2. 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).


网站公告

今日签到

点亮在社区的每一天
去签到