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

如何为WP All Import导入的WooCommerce尺码变体添加关联自定义标签?

How to Add Custom Size Labels (e.g. 50 (15.9)) to WooCommerce Variants Imported via WP All Import

Hey Ely, totally get what you’re trying to do—adding region-specific size annotations to your existing variant attributes without breaking the WP All Import setup you already have. Let’s walk through a few solid, actionable solutions that fit your needs:

Option 1: Map Labels Directly During Import (Cleanest for New/Re-Imports)

If you’re open to re-importing your products or setting up future imports to handle this automatically, you can use a simple PHP snippet in WP All Import to map raw sizes to your labeled versions:

  1. First, create a key-value pair of your size conversions (e.g., 50 → 15.9, 52 → 16.2).
  2. Add this snippet to your theme’s functions.php file or a custom plugin:
    function map_size_with_label($raw_size) {
        $size_conversions = array(
            '50' => '50 (15.9)',
            '52' => '52 (16.2)',
            // Add all your size pairs here
        );
        // Return the labeled version if it exists, else the original size
        return isset($size_conversions[$raw_size]) ? $size_conversions[$raw_size] : $raw_size;
    }
    
  3. In WP All Import, when mapping your size attribute field, instead of using the raw source value, call the function like this:
    [map_size_with_label({your_source_size_field})]
    This will create variants with the labeled size attribute right from the start, no extra steps needed post-import.

Option 2: Custom Fields + Database Mapping (Best for Existing Products)

If your products are already imported and you don’t want to re-import them, you can tie custom labels to your existing size attributes using custom fields and WooCommerce hooks:

  1. Add Custom Fields to Size Attributes:
    • Use a plugin like Advanced Custom Fields (ACF) to create a text field (e.g., custom_size_label) and attach it to your pa_size product attribute terms.
    • Go to Products → Attributes → Size → Edit Terms, and for each size (50, 52, etc.), fill in the corresponding regional label (15.9, 16.2, etc.). If you have lots of terms, you can bulk update them via WP All Import by importing a CSV with term slugs and custom field values.
  2. Hook to Display the Label:
    Add this snippet to your theme/functions.php to modify how the size option displays on the frontend:
    add_filter('woocommerce_variation_option_name', 'append_custom_size_label', 10, 1);
    function append_custom_size_label($option_name) {
        // Get the term object for the current size option
        $size_term = get_term_by('name', $option_name, 'pa_size');
        if ($size_term) {
            // Pull the custom label from the term's meta
            $custom_label = get_term_meta($size_term->term_id, 'custom_size_label', true);
            if (!empty($custom_label)) {
                return $option_name . ' (' . $custom_label . ')';
            }
        }
        // Fallback to original name if no label exists
        return $option_name;
    }
    

This keeps your original attribute values intact (so variants still work as expected) but shows the combined label to customers.

Option 3: Edit Attribute Term Names (Quickest Fix)

If you don’t need to keep the raw size name separate anywhere, just edit the term names directly:

  • Go to Products → Attributes → Size → Edit Terms.
  • For each term, change the "Name" field to 50 (15.9) (keep the "Slug" as 50 to preserve variant associations).
  • For bulk edits, use WP All Import to import a CSV with term slugs and updated names—this is way faster than editing one by one.

Bonus: Region-Specific Labels

If you need to show different labels based on the user’s country, pair the custom field approach with a geolocation plugin (like WooCommerce Geolocation) and modify the hook to check the user’s country before returning the label.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:57:57