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

如何批量为WooCommerce含Outright/Exchange属性的产品添加属性描述?

批量为WooCommerce可变产品属性添加描述的解决方案

针对你有1000+个可变产品,需要批量给Outright和Exchange属性添加描述的需求,以下是三个可行方案:

方案1:PHP代码片段批量更新

适合有基础开发能力的用户,直接通过代码遍历产品并更新属性描述:

add_action('admin_init', 'bulk_update_variation_attribute_descriptions');

function bulk_update_variation_attribute_descriptions() {
    // 仅管理员可执行
    if (!current_user_can('manage_options')) return;

    // 替换为你的属性slug(WooCommerce属性默认带pa_前缀)
    $attribute_slug = 'pa_purchase-type';
    // 定义属性术语对应的描述
    $term_descriptions = [
        'outright' => '直接购买产品,无需退回旧部件',
        'exchange' => '购买新产品并退回旧部件,享受以旧换新权益'
    ];

    // 筛选包含目标属性的可变产品
    $product_query = new WP_Query([
        'post_type' => 'product',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'tax_query' => [
            [
                'taxonomy' => $attribute_slug,
                'field' => 'slug',
                'terms' => array_keys($term_descriptions)
            ]
        ]
    ]);

    if ($product_query->have_posts()) {
        while ($product_query->have_posts()) {
            $product_query->the_post();
            $wc_product = wc_get_product(get_the_ID());
            
            if (!$wc_product || !$wc_product->is_type('variable')) continue;

            // 获取产品关联的属性术语
            $attribute_terms = $wc_product->get_attribute($attribute_slug);
            if (empty($attribute_terms)) continue;

            // 更新每个术语的描述
            foreach ($wc_product->get_attribute_taxonomy_terms($attribute_slug) as $term) {
                if (isset($term_descriptions[$term->slug])) {
                    wp_update_term(
                        $term->term_id,
                        $attribute_slug,
                        ['description' => $term_descriptions[$term->slug]]
                    );
                }
            }
        }
        wp_reset_postdata();
        // 执行成功提示(执行一次后建议注释或删除此行及add_action)
        // add_action('admin_notices', function() { echo '<div class="notice notice-success"><p>属性描述批量更新完成</p></div>'; });
    }

    // 执行一次后,请注释掉顶部的add_action,避免每次后台加载重复执行
}

使用说明:

  • 将代码添加到当前主题的functions.php文件,或使用代码片段插件(如Code Snippets)执行
  • 务必替换$attribute_slug为你实际的属性slug(在WP后台“产品>属性”中查看,例如属性名为“购买类型”,slug通常是purchase-type,WooCommerce会自动添加pa_前缀)
  • 修改$term_descriptions中的描述内容为你需要的文本
  • 执行一次后,立即注释或删除add_action('admin_init', ...)这一行,防止重复执行

方案2:预处理CSV文件重新导入

若你更熟悉Excel操作,可以修改CSV后重新导入更新:

  • 打开现有产品CSV,新增一列,列名设为Attribute 1 Description(如果这是第一个属性,对应你的购买类型属性)
  • 对每个可变产品行,按格式填写描述:Outright:直接购买产品;Exchange:购买产品并退回旧部件
  • 进入WP后台“产品>导入”,选择修改后的CSV,勾选“更新现有产品”选项,完成导入后属性描述会自动更新

方案3:批量编辑插件实现

适合无开发基础的用户,使用WooCommerce批量编辑插件:

  • 安装并激活支持属性描述编辑的插件(如WooCommerce Bulk Edit Products, Prices & Attributes)
  • 进入插件的批量编辑页面,筛选出所有包含Outright和Exchange属性的可变产品
  • 在属性编辑区域找到描述字段,批量设置对应的文本内容,保存即可完成更新

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 02:56:32