Skip to content

Instantly share code, notes, and snippets.

@xmunoz
Last active May 20, 2024 14:21
Show Gist options
  • Save xmunoz/bb2b8392ac3c38b0a7e395649b723b6e to your computer and use it in GitHub Desktop.
Save xmunoz/bb2b8392ac3c38b0a7e395649b723b6e to your computer and use it in GitHub Desktop.
WooCommerceCustomerToShopify.py
import csv
import sys
# Define the path to the WooCommerce CSV file and the output Shopify CSV file
woo_csv_path = sys.argv[1]
shopify_csv_path = 'ShopifyCustomerUpload.csv'
# Define the mapping from WooCommerce to Shopify column names
column_mapping = {
'first_name': 'First Name',
'last_name': 'Last Name',
'user_email': 'Email',
'billing_company': 'Default Address Company',
'billing_address_1': 'Default Address Address1',
'billing_address_2': 'Default Address Address2',
'billing_city': 'Default Address City',
'billing_state': 'Default Address Province Code',
'billing_country': 'Default Address Country Code',
'billing_postcode': 'Default Address Zip',
'billing_phone': 'Phone'
}
# Read the WooCommerce CSV and write to the Shopify CSV with updated headers
with open(woo_csv_path, mode='r', newline='', encoding='utf-8') as woo_file:
reader = csv.DictReader(woo_file)
# Create a new header list based on the column mapping
new_headers = [column_mapping.get(header, header) for header in reader.fieldnames]
with open(shopify_csv_path, mode='w', newline='', encoding='utf-8') as shopify_file:
writer = csv.DictWriter(shopify_file, fieldnames=new_headers)
writer.writeheader()
for row in reader:
# Create a new row dictionary based on the column mapping
new_row = {column_mapping.get(key, key): value for key, value in row.items()}
writer.writerow(new_row)
print(f"CSV headings have been updated and saved to {shopify_csv_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment