• Resolved jonrowe

    (@jonrowe)


    I found this code below, (editted slightly to match my usage on another forum thread and inserted it into my themes functions.php file..

    My needs are slightly different though. I need to add custom data for 2 different tabs. Crossovers as well as Specs. The below has worked well for me for crossovers. How would I add a second tab to the code to allow for the import of specs in a separate tab.

    /**
    * Register the ‘Custom Tabs’ column in the importer.
    *
    * @param array $options
    * @return array $options
    */
    function add_column_to_importer($options)
    {
    // column slug => crossovers
    $options[‘yikes_custom_tabs’] = ‘Custom Tabs’;

    return $options;
    }
    add_filter(‘woocommerce_csv_product_import_mapping_options’, ‘add_column_to_importer’);
    /**
    * Add automatic mapping support for ‘Custom Tabs’.
    * This will automatically select the correct mapping for columns named ‘Custom Tabs’.
    *
    * @param array $columns
    * @return array $columns
    */
    function add_column_to_mapping_screen($columns)
    {
    // potential column name => crossovers
    $columns[‘Custom Tabs’] = ‘yikes_custom_tabs’;

    return $columns;
    }
    add_filter(‘woocommerce_csv_product_import_mapping_default_columns’, ‘add_column_to_mapping_screen’);
    /**
    * Process the data read from the CSV file
    * This just saves the decoded JSON in meta data, but you can do anything you want here with the data.
    *
    * @param WC_Product $object – Product being imported or updated.
    * @param array $data – CSV data read for the product.
    * @return WC_Product $object
    */
    function process_import($object, $data)
    {
    if (!empty($data[‘yikes_custom_tabs’])) {
    $arr = json_decode($data[‘yikes_custom_tabs’], true);
    $object->update_meta_data(‘yikes_woo_products_tabs’, $arr);
    }

    return $object;
    }
    add_filter(‘woocommerce_product_import_pre_insert_product_object’, ‘process_import’, 10, 2);

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Importing More Than One Custom Tab Per Product’ is closed to new replies.