How to add Custom Field in Woo-commerce export import

Custom meta fields in WooCommerce allow you to add additional information and data to your products, such as size, color, or any other custom attribute. However, exporting or importing products with custom meta fields can be a daunting task, especially if you don’t have prior experience. In this tutorial, we’ll guide you through the process of adding custom meta in WooCommerce export/import, step-by-step. With this knowledge, you’ll be able to manage and transfer your product data with ease, making your store more efficient and streamlined. So, let’s dive in and learn how to add custom meta fields to your WooCommerce products for export and import!

// ----------------------------------------------------------------
// Import Column
function add_custom_column_to_importer( $options ) {

	// column slug => column name
	$options['custom_column'] = 'Custom Column';

	return $options;
}
add_filter( 'woocommerce_csv_product_import_mapping_options', 'add_custom_column_to_importer' );


function add_custom_column_to_woocommerce_import( $columns ) {
	
	// potential column name => column slug
	$columns['Custom Column'] = 'custom_column';

	return $columns;
}
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'add_custom_column_to_woocommerce_import' );


function custom_import_in_woocommerce( $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', 'custom_import_in_woocommerce', 10, 2 );

// ----------------------------------------------------------------
// Export Column
function add_export_custom_column( $columns ) {

	// column slug => column name
	$columns['custom_column'] = 'Custom Column';

	return $columns;
}
add_filter( 'woocommerce_product_export_column_names', 'add_export_custom_column' );
add_filter( 'woocommerce_product_export_product_default_columns', 'add_export_custom_column' );

function add_custom_column_export_data( $value, $product ) {
	$value = $product->get_meta( 'custom_column', true, 'edit' );
	return $value;
}
add_filter( 'woocommerce_product_export_product_column_custom_column', 'add_custom_column_export_data', 10, 2 );
Scroll to Top