Importing files. need more access to custom fileds

This topic has 19 replies, 2 voices, and was last updated 1 weeks, 1 days ago ago by Luca Rossi

  • Avatar: Rok
    Rok
    Participant
    June 19, 2025 at 07:16

    Hi,
    I’m importing products via CSV, but I can’t locate a way to include one important field. In the Product Settings tab, there’s a section called “Bought Together”. While I’m able to assign values for cross-sells and upsells, I can’t find how to populate the Bought Together field during the import.

    Could you please advise how to add data to this field via CSV or if there’s a workaround?
    Added screenshots w/ existed values and value what I need to add for working CSV
    Thanks!

    Files is visible for topic creator and
    support staff only.
    18 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    June 19, 2025 at 10:35

    Dear @Rok,

    Thank you for reaching out.

    Please note that the default import functionality in WooCommerce has certain limitations, particularly when it comes to importing custom columns.

    To address this, you may consider using the following code snippet, which allows for the addition of custom import columns:
    https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter#adding-custom-import-columns-developers

    Alternatively, you might find the following plugins helpful for more advanced import options:

    – WooCommerce XML/CSV Product Import: https://wordpress.org/plugins/woocommerce-xml-csv-product-import/ (Please note that some features may require the Pro version.)
    – Product Import Export for WooCommerce: https://wordpress.org/plugins/product-import-export-for-woo/

    We hope this information proves useful. Should you have any further questions, please do not hesitate to contact us.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 20, 2025 at 05:43

    Do you have access for implement those updates from GitHub?

    Avatar: Justin
    Luca Rossi
    Support staff
    June 20, 2025 at 06:52

    Dear @Rok,

    We hope this message finds you well.

    Could you please clarify what you mean by “access”? The code in question appears to be publicly available, as shown below:

    
    /**
     * Register the 'Custom Column' column in the importer.
     *
     * @param array $options
     * @return array $options
     */
    function add_column_to_importer( $options ) {
        // column slug => column name
        $options['custom_column'] = 'Custom Column';
        return $options;
    }
    add_filter( 'woocommerce_csv_product_import_mapping_options', 'add_column_to_importer' );
    
    /**
     * Add automatic mapping support for 'Custom Column'.
     * This will automatically select the correct mapping for columns named 'Custom Column' or 'custom column'.
     *
     * @param array $columns
     * @return array $columns
     */
    function add_column_to_mapping_screen( $columns ) {
        // potential column name => column slug
        $columns['Custom Column'] = 'custom_column';
        $columns['custom column'] = 'custom_column';
        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 value 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['custom_column'] ) ) {
            $object->update_meta_data( 'custom_column', $data['custom_column'] );
        }
        return $object;
    }
    add_filter( 'woocommerce_product_import_pre_insert_product_object', 'process_import', 10, 2 );
    

    We would appreciate it if you could provide further details regarding your request.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 22, 2025 at 15:28

    “Access” I meant if you can add it in my project

    Avatar: Rok
    Rok
    Participant
    June 23, 2025 at 00:18

    what field is responsible for “Bought together”?

    I tested:
    et_bought_together_product_data
    bought_together_product_data
    bought_together_ids

    All of them didnt update the correct tab

    My code:
    //Custom field csv start

    // 1. Add custom column to the importer mapping screen
    function add_column_to_importer( $options ) {
    $options[‘bought_together_ids’] = ‘Bought together’;
    return $options;
    }
    add_filter( ‘woocommerce_csv_product_import_mapping_options’, ‘add_column_to_importer’ );

    // 2. Automatically map “Bought together” column in CSV to our custom key
    function add_column_to_mapping_screen( $columns ) {
    $columns[‘Bought together’] = ‘bought_together_ids’;
    return $columns;
    }
    add_filter( ‘woocommerce_csv_product_import_mapping_default_columns’, ‘add_column_to_mapping_screen’ );

    // 3. Save the imported data to product meta
    function process_imported_bought_together( $object, $data ) {
    if ( ! empty( $data[‘bought_together_ids’] ) ) {
    $object->update_meta_data( ‘bought_together_ids’, $data[‘bought_together_ids’] );
    }
    return $object;
    }
    add_filter( ‘woocommerce_product_import_pre_insert_product_object’, ‘process_imported_bought_together’, 10, 2 );

    //Custom field csv end

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    June 23, 2025 at 04:19

    Dear @Rok,

    We hope this message finds you well.

    Please note that the correct custom field name for the “Bought Together” feature is: et_bought_together_ids

    Kindly let us know if this works for you or if you need any further assistance.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 23, 2025 at 07:32

    No, it doesnt work. see screenshot.

    Code (edit theme-> functions.php. you can check):

    //Custom field csv start
    // 1. Add custom column to WooCommerce importer options
    function add_column_to_importer( $options ) {
    $options[‘et_bought_together_ids’] = ‘Bought together’;
    return $options;
    }
    add_filter( ‘woocommerce_csv_product_import_mapping_options’, ‘add_column_to_importer’ );

    // 2. Auto-map the column “Bought together” in CSV to the correct key
    function add_column_to_mapping_screen( $columns ) {
    $columns[‘Bought together’] = ‘et_bought_together_ids’;
    return $columns;
    }
    add_filter( ‘woocommerce_csv_product_import_mapping_default_columns’, ‘add_column_to_mapping_screen’ );

    // 3. Save the imported value as custom meta for the product
    function process_imported_bought_together( $object, $data ) {
    if ( ! empty( $data[‘et_bought_together_ids’] ) ) {
    $object->update_meta_data( ‘et_bought_together_ids’, $data[‘et_bought_together_ids’] );
    }
    return $object;
    }
    add_filter( ‘woocommerce_product_import_pre_insert_product_object’, ‘process_imported_bought_together’, 10, 2 );

    //Custom field csv end

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    June 23, 2025 at 08:52

    Dear @Rok,

    Regarding the following line of code:

    
    $object->update_meta_data( 'et_bought_together_ids', $data['et_bought_together_ids'] );
    

    We kindly request that you update the meta key name to:

    
    '_et_bought_together_ids'
    

    We hope this helps. Please let us know if you have any questions or need further assistance.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 23, 2025 at 14:24

    it looks like this code doesn’t work:
    Can you please connect and test it?
    I tried to add an import template, but it was not possible. Sharing the screen. Ext. *.csv

    //Custom field csv start
    // 1. Add custom column to WooCommerce importer options
    function add_column_to_importer( $options ) {
    $options[‘et_bought_together_ids’] = ‘Bought together’;
    return $options;
    }
    add_filter( ‘woocommerce_csv_product_import_mapping_options’, ‘add_column_to_importer’ );

    // 2. Auto-map the column “Bought together” in CSV to the correct key
    function add_column_to_mapping_screen( $columns ) {
    $columns[‘Bought together’] = ‘et_bought_together_ids’;
    return $columns;
    }
    add_filter( ‘woocommerce_csv_product_import_mapping_default_columns’, ‘add_column_to_mapping_screen’ );

    // 3. Save the imported value as custom meta for the product
    function process_imported_bought_together( $object, $data ) {
    if ( ! empty( $data[‘et_bought_together_ids’] ) ) {
    $object->update_meta_data( ‘_et_bought_together_ids’, $data[‘et_bought_together_ids’] );
    }
    return $object;
    }
    add_filter( ‘woocommerce_product_import_pre_insert_product_object’, ‘process_imported_bought_together’, 10, 2 );

    //Custom field csv end

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    June 24, 2025 at 06:22

    Dear @Rok,

    Please note that debugging the custom code you provided would require a significant amount of time. As such, we kindly recommend contacting our development team for further assistance.

    Kindly be advised that custom code modifications fall outside the scope of our standard support services. However, you may submit a request through our Customization Panel at the following link: https://www.8theme.com/account/#etheme_customization_panel. Please note that customization services may incur additional charges.

    If you have any further questions or need additional assistance, please do not hesitate to contact us.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 24, 2025 at 06:26

    WHAT ARE YOU TALKING ABOUT???? “BOUGHT TOGETHER” TAB EXISTS BY DEFAULT. THAT CASE, THEAT IT DOESN’T WORK IS NOT MY PROBLEM!!!!!!
    THE INTEGRATION WAS NOT FINISHED IN THEME, AND I’M ASKING A BASIC THING THE NAME OF THE CUSTOM FIELD!

    Avatar: Justin
    Luca Rossi
    Support staff
    June 24, 2025 at 11:07

    Dear Rok,

    We hope this message finds you well.

    Our development team has prepared a potential solution regarding the import/export functionality for Frequently Bought Together (FBT) products.

    Please add this code to your child theme’s functions.php file:

    // 1. Add column to importer & exporter
    add_filter( 'woocommerce_csv_product_import_mapping_options', 'etheme_add_column_to_importer_exporter', 10 );
    add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'etheme_add_default_column_mapping', 10 );
    add_filter( 'woocommerce_product_export_column_names', 'etheme_add_column_to_importer_exporter', 10 );
    add_filter( 'woocommerce_product_export_product_default_columns', 'etheme_add_column_to_importer_exporter', 10 );
    
    // 2. Export field value
    add_filter( 'woocommerce_product_export_product_column_et_bought_together', 'etheme_get_column_value_bought_together_ids', 10, 2 );
    
    // 3. Register import formatting
    add_filter( 'woocommerce_product_importer_formatting_callbacks', function( $callbacks ) {
        $callbacks['et_bought_together'] = function( $value ) {
            return array_filter( array_map( 'absint', explode( ',', $value ) ) );
        };
        return $callbacks;
    });
    
    // 4. Process import field and save as meta
    add_action( 'woocommerce_product_import_inserted_product_object', 'etheme_process_import', 10, 2 );
    
    function etheme_process_import( $product, $data ) {
        if ( ! empty( $data['et_bought_together'] ) ) {
            update_post_meta( $product->get_id(), '_et_bought_together_slugs', explode('::et_separator::', $data['et_bought_together']) );
            $product->save(); // <- this is required to persist the meta!
        }
    }
    
    // 5. Default column mapping
    function etheme_add_default_column_mapping( $mappings ) {
        $mappings['Bought Together IDs'] = 'et_bought_together';
        return $mappings;
    }
    
    // 6. Register column for import/export
    function etheme_add_column_to_importer_exporter( $columns ) {
        $columns['et_bought_together'] = 'Bought Together IDs';
        return $columns;
    }
    
    // 7. Get export value
    function etheme_get_column_value_bought_together_ids( $value, $product ) {
        $ids = get_post_meta( $product->get_id(), '_et_bought_together_ids', true );
    
        if ( ! is_array( $ids ) || empty( $ids ) ) {
            return '';
        }
    
        $slugs = array();
    
        foreach ( $ids as $id ) {
            $post = get_post( $id );
            if ( $post && $post->post_type === 'product' ) {
                $slugs[] = $post->post_name;
            }
        }
    
        return implode( '::et_separator::', $slugs );
    }
    
    // add_action( 'admin_init', 'etheme_convert_bought_together_slugs_to_ids' );
    
    function etheme_convert_bought_together_slugs_to_ids() {
    	if ( get_option( 'et_fbt_slugs_import_convert_done', false ) ) {
    		return;
    	}
    
    	$args = array(
    		'post_type' => 'product',
    		'posts_per_page' => -1,
    		'meta_query' => array(
    			array(
    				'key'     => '_et_bought_together_slugs',
    				'compare' => 'EXISTS'
    			)
    		)
    	);
    	$query = new WP_Query( $args );
    
    	foreach ( $query->posts as $product_post ) {
    		$product_id = $product_post->ID;
    		$slugs_raw = get_post_meta( $product_id, '_et_bought_together_slugs', true );
    		if ( ! $slugs_raw ) continue;
    
    		$slugs = array_map( 'trim', explode( '::et_separator::', $slugs_raw ) );
    		$ids = array();
    
    		foreach ( $slugs as $slug ) {
    			$related_product = get_page_by_path( $slug, OBJECT, 'product' );
    			if ( $related_product ) {
    				$ids[] = $related_product->ID;
    			}
    		}
    
    		if ( $ids ) {
    			update_post_meta( $product_id, '_et_bought_together_ids', $ids );
    		}
    		// optionally delete temp field
    		delete_post_meta( $product_id, '_et_bought_together_slugs' );
    	}
    
    	// Prevent reprocessing
    	update_option( 'et_fbt_slugs_import_convert_done', true );
    }
    
    add_filter('woocommerce_debug_tools', function($settings) {
       $settings['convert_et_fbt_slugs_on_import'] = array(
            'name'   => __( 'Convert fbt products after import', 'xstore' ),
            'button' => __( 'Converte', 'xstore' ),
            'desc'   => __( 'This tool will update products with actual fbt products after import process.', 'xstore' ),
            'callback' => 'etheme_convert_bought_together_slugs_to_ids'
        );
        return $settings;
    });

    Kindly ensure that the same code is applied to both the export and import websites. We have tested the solution locally using two separate environments.

    The process involves the following steps:

    1. Export products along with all associated data.
    2. Import the products into another website.
    3. Since FBT products are stored using product IDs, they cannot be correctly mapped during import due to the generation of new IDs. To address this, We have implemented a method to import FBT products using their slugs instead.

    After importing, please navigate to WooCommerce → Status → Tools and run the tool as shown in the following screenshot: https://prnt.sc/QOqGxA8hbs83. This will convert the FBT product slugs to the corresponding new product IDs.

    Please let us know if you encounter any issues.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 24, 2025 at 14:25

    Hi there
    I have updated, but it looks like it doesn’t work.
    Here is a screen recording.
    If you know it’s working, you may need to update the main theme and share the update with everyone. This feature will save a lot of time. Manually, it takes at least 2 minutes for each item to update.

    https://www.loom.com/share/e9d106bfed53475e92ebd85faca21d0f?sid=d162af9f-955e-4ac4-abcf-618d8096f9c8

    Avatar: Justin
    Luca Rossi
    Support staff
    June 24, 2025 at 17:17

    Dear @Rok,

    We hope this message finds you well.

    We have noticed that your CSV file is currently using product slugs instead of product IDs for the “Bought Together” feature. We kindly ask you to update these to use product IDs instead, as this will ensure proper functionality.

    After importing, please navigate to WooCommerce → Status → Tools and run the tool as shown in the following screenshot: https://prnt.sc/QOqGxA8hbs83. This will convert the FBT product slugs to the corresponding new product IDs.

    If it still doesn’t work, could you please share your website URL along with admin access credentials? This will allow us to take a closer look and assist you more effectively.

    Thank you for your cooperation.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 24, 2025 at 17:23

    Just to clarify, does that ID has to be of updated file?
    If so, what happens when I add a new item?

    Avatar: Justin
    Luca Rossi
    Support staff
    June 24, 2025 at 17:27

    Dear Rok,

    Please note that the CSV file should contain product IDs rather than product slugs.

    Additionally, when importing the “Bought Together” products to existing items, please ensure that the associated products already exist in the system.

    Should you have any further questions, feel free to reach out.

    Best regards,
    The 8Theme Team

    Avatar: Rok
    Rok
    Participant
    June 24, 2025 at 17:37

    But why can’t I import them within the initial import, the same as crosssell and upsell products???? These items don’t require additional manipulations.
    Cross-sell and upsell work very well, without any issues. As for me, it looks like we have to add one more row, functions with the same functionality already exist. Also, you should know that it also works even if items do not exist in the base yet.

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    June 25, 2025 at 06:22

    Dear @Rok,

    In order to investigate the issue further and provide the most effective assistance, we kindly request temporary access to your WordPress admin panel and FTP.

    To grant WordPress admin access, please create a new user account with Administrator privileges via your WordPress Dashboard. Once the account has been created, you may securely share the login credentials with us through the Private Content section.

    For FTP access, we would appreciate it if you could provide the following details:

    – FTP Host
    – FTP Username
    – FTP Password
    – FTP Port

    If you are unsure how to obtain or create these credentials, we recommend contacting your hosting provider for guidance.

    Additionally, we kindly ask you to share the CSV file export that you mentioned, so we can use it for testing purposes.

    Thank you in advance for your cooperation. We look forward to resolving the issue promptly.

    Best regards,
    The 8Theme Team

  • Viewing 19 results - 1 through 19 (of 19 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.