You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为所有WooCommerce商品页面添加默认描述(图片/备注文本)

Adding a Default Description to All WooCommerce Product Pages

Absolutely! You can easily add a default description (supporting both text notes and images) to every WooCommerce product page, and choose to place it either above or below the existing product description. Below are two practical, reliable methods to achieve this:

Method 1: Use WooCommerce Hooks (Simplest Approach)

WooCommerce provides dedicated hooks that let you inject content directly before or after the product description. This method doesn’t require extra plugins and gives you full control over the content.

Add the following code to your child theme’s functions.php file (or use a custom code snippet plugin like Code Snippets to avoid losing changes when your theme updates):

// Add default description ABOVE the existing product description
add_action('woocommerce_before_single_product_description', 'display_default_product_description_above');

function display_default_product_description_above() {
    // Customize this HTML to include your text, images, or formatting
    $default_content = '<div class="default-product-info">
        <h4>📦 Shipping & Returns Guarantee</h4>
        <p>All orders ship within 24 hours! <img src="https://your-domain.com/wp-content/uploads/2024/06/shipping-icon.png" alt="Fast Shipping" style="max-width: 80px; vertical-align: middle; margin-left: 10px;"></p>
        <p>We offer a 30-day hassle-free return policy for all unused products.</p>
    </div>';

    echo $default_content;
}

// Uncomment the code below to add default description BELOW instead
/*
add_action('woocommerce_after_single_product_description', 'display_default_product_description_below');

function display_default_product_description_below() {
    $default_content = '<div class="default-product-info">
        <h4>🔍 Quality Assurance</h4>
        <p>Every product undergoes a strict 3-step quality check before reaching you.</p>
    </div>';

    echo $default_content;
}

Key Tips for This Method:

  • Replace the $default_content HTML with your own text and image URLs. You can use any valid HTML here (lists, links, styling, etc.).
  • Add custom CSS to the .default-product-info class in your theme’s style.css to match your site’s design (e.g., adjust margins, colors, or font sizes).
  • Adjust the hook priority (add a third parameter to add_action, like 15) if your content appears in the wrong order relative to other elements.

Method 2: Category-Specific Default Descriptions (More Flexible)

If you want different default descriptions for products in different categories, you can use custom fields paired with WooCommerce hooks. This requires a plugin like Advanced Custom Fields (ACF) to add custom fields to your product categories.

  1. First, use ACF to create a new field group for product categories, adding a WYSIWYG editor field (named something like default_category_description) to store the default content.
  2. Add this code to your child theme’s functions.php or code snippet plugin:
add_action('woocommerce_before_single_product_description', 'display_category_default_description');

function display_category_default_description() {
    global $product;
    $product_categories = wp_get_post_terms($product->get_id(), 'product_cat');

    if (!empty($product_categories)) {
        // Loop through the product's categories and grab the first one with a default description
        foreach ($product_categories as $category) {
            $default_desc = get_field('default_category_description', 'product_cat_' . $category->term_id);
            
            if ($default_desc) {
                echo '<div class="category-default-desc">' . $default_desc . '</div>';
                break; // Stop after the first matching category
            }
        }
    }
}

How This Works:

  • The code checks which category the current product belongs to, then pulls the custom default description you set for that category via ACF.
  • You can place this content above or below the product description by swapping out woocommerce_before_single_product_description with woocommerce_after_single_product_description.

Final Notes

  • Always test your changes on a staging site first to avoid breaking your live store.
  • If you’re not comfortable editing code, look for a WooCommerce plugin that offers "global product description" functionality (but code-based methods are lighter and more customizable).

内容的提问来源于stack exchange,提问作者Ziaul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:25:29