首页 > 解决方案 > 自定义 woocommerce 产品字段不适用于 CSV 导入

问题描述

我以这种方式为我的产品创建了一个自定义字段:

// The code for displaying WooCommerce Product Custom Fields
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields' ); 
// Following code Saves  WooCommerce Product Custom Fields
add_action( 'woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save' );
function woocommerce_product_custom_fields () {
    global $woocommerce, $post;
    echo '<div class=" product_custom_field ">';
    // Custom Product Number Field
    woocommerce_wp_text_input(
        array(
            'id' => '_shipping_days_field',
            'placeholder' => 'Días de entrega',
            'label' => __('Días estimados de entrega', 'woocommerce'),
            'type' => 'number',
            'custom_attributes' => array(
                'step' => 'any',
                'min' => '1'
            )
        )
    );
    echo '</div>';
}

function woocommerce_product_custom_fields_save($post_id){
    // Custom Product Number Field
    $shipping_days = $_POST['_shipping_days_field'];
    if (!empty($shipping_days))
        update_post_meta($post_id, '_shipping_days_field', esc_attr($shipping_days));
}

这在前端管理员上工作正常,它显示字段并保存它,但它不适用于 CSV 导入,我无法在我的 CSV 映射中指定该字段。有没有一种方法可以创建也适用于 CSV 导入的自定义字段?

标签: wordpresscsvwoocommerce

解决方案


我实际上解决了它,在映射上您应该选择 Meta Attributes,并且 CSV 列上的标签必须如下:

meta:your_custom_field


推荐阅读