Skip to content

Forum in maintenance, we will back soon 🙂

Woocommerce Product...
 
Notifications
Clear all

Woocommerce Product Updater

14 Posts
4 Users
2 Reactions
62 Views
(@rajsidhu)
Posts: 34
Eminent Member
Topic starter
 

Hi Hasan,

I have a challenge for you which i am sure you would be able to solve for me and i know it would be so useful for a lot of other people who use Woocommerce or are learning Python.

So i run a Woocommerce store and i had a brick wall i had to over come. So i though i'd ask ChatGPT if there was a way to solve my issue.

Here is my question and the answer i got back from ChatGPT:-

i have a problem i need to solve. I have a woocommerce website. I have a supplier who can supply me with 1000's of products. They have given me a product file which i have uploaded to my site. They also have a file that lives on their ftp, password protected site that is updated 2 times a day with stock quantities and prices. The file is in csv format I need to setup an automated way of making sure the sock levels and the pricing on my site are updated regularly to reflect the suppliers file. The solution must be totally hands off, once setup, and reliable. It should also look for products whos price or stock has changed, since the last update and only update those products on my site. What solution do you propose?
ChatGPT

To solve this problem, you need a solution that automates the process of downloading the CSV file from your supplier's FTP server, comparing it with your current WooCommerce product data, and updating only the products that have had changes in stock levels or prices. Here is a proposed solution:

Tools Needed:

  1. WooCommerce REST API: To interact with your WooCommerce store programmatically.
  2. Python: For scripting the automation process.
  3. Scheduled Task/Job Scheduler: To run the script at regular intervals (e.g., cron job for Unix/Linux, Task Scheduler for Windows).

Steps to Implement the Solution:

  1. Set Up Access to FTP Server:

    • Use Python's ftplib library to connect to the supplier's FTP server and download the CSV file.
  2. Process the CSV File:

    • Use pandas or csv library in Python to read the CSV file and store it in a DataFrame or dictionary for easy comparison.
  3. Compare with Existing Product Data:

    • Use WooCommerce REST API to fetch current product data from your site.
    • Compare the stock levels and prices from the downloaded CSV with the current data on your WooCommerce store.
  4. Update Changed Products:

    • Use WooCommerce REST API to update only the products that have changes in stock levels or prices.
  5. Schedule the Script:

    • Use a cron job (Linux) or Task Scheduler (Windows) to run the script at the desired intervals (e.g., twice a day).

Example Python Script:

Here is a simplified example of how the script might look:

python

import ftplib
import pandas as pd
import requests
import json
from woocommerce import API

# WooCommerce API credentials
wcapi = API(
url="https://your-woocommerce-site.com",
consumer_key="ck_your_consumer_key",
consumer_secret="cs_your_consumer_secret",
version="wc/v3"
)

# FTP server credentials
ftp_server = "ftp.supplier.com"
ftp_user = "username"
ftp_password = "password"
remote_file = "supplier_data.csv"
local_file = "local_supplier_data.csv"

# Download file from FTP
def download_csv():
with ftplib.FTP(ftp_server) as ftp:
ftp.login(user=ftp_user, passwd=ftp_password)
with open(local_file, 'wb') as f:
ftp.retrbinary(f'RETR {remotes_file}', f.write)

# Update WooCommerce products
def update_products():
# Read the downloaded CSV file
supplier_data = pd.read_csv(local_file)

for index, row in supplier_data.iterrows():
product_id = row['product_id']
new_stock = row['stock']
new_price = row['price']

# Fetch current product data from WooCommerce
product = wcapi.get(f"products/{product_id}").json()
current_stock = product['stock_quantity']
current_price = product['price']

# Check for changes
if new_stock != current_stock or new_price != current_price:
data = {
"stock_quantity": new_stock,
"regular_price": str(new_price)
}
wcapi.put(f"products/{product_id}", data)

# Main function
if __name__ == "__main__":
download_csv()
update_products()

Scheduling the Script:

For Linux (using cron):

  1. Open the crontab file:
    sh

    crontab -e
  2. Add the following line to run the script twice a day:
    sh

    0 0,12 * * * /usr/bin/python3 /path/to/your_script.py

For Windows (using Task Scheduler):

  1. Open Task Scheduler and create a new task.
  2. Set the trigger to run twice a day.
  3. Set the action to run the Python script with the Python interpreter.

Conclusion:

This solution leverages Python and the WooCommerce REST API to automate the update process. Once set up, it will run at the specified intervals, download the latest CSV file, compare it with the current data, and update only the products that have changed, ensuring your WooCommerce site always reflects the latest stock levels and prices from your supplier.

Would you be able to create a video that would take this problem and use the instructions provided by ChatGPT and show us how we can make this solution work?

I think that would be a great project for us to learn from.

Thanks in advance Hasan @admin 

 
Posted : 07/11/2024 11:41 am
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@rajsidhu you need a dedicated server to process the data like this. The amount of data can quickly overwhelm any VPS. There are also a lot of DevOps that you also need to consider. 

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 07/12/2024 3:27 am
Hasan Aboul Hasan
(@admin)
Posts: 1208
Member Admin
 

so you need to fetch the data from the target server and then update woocommerce; this definitely needs a custom solution and custom coding, I don't think there is an automated no code approach

you will need to read the CSV, and using the woocommerce hooks and functions, you will update the products. 

can you send like 5-10 records of the CSV to see how it is structured? 

 
Posted : 07/12/2024 4:38 pm
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

And it's very much dependent on the data service provider; so you need custom code for each different service provider.

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 07/12/2024 11:42 pm
(@rajsidhu)
Posts: 34
Eminent Member
Topic starter
 

@admin Here is an Excel spreadsheet that contains the structure of the products to be uploaded.

Once they are uploaded, the products will be available to buy on our Woocommerce website.

But every day this file will be update with stock and any price updates so the automation will be just for the updated info. coming through every day.

Hope that makes sense.

 

 
Posted : 07/16/2024 2:03 pm
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@rajsidhu is it always going to be this one sheet? If so, then this would be a good fit for automation tools like Make.

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 07/16/2024 4:29 pm
Hasan Aboul Hasan
(@admin)
Posts: 1208
Member Admin
 

@rajsidhu yeah as @ssadvisor mentioned, you can use no code automation tools like Make to read and update the woocomerce products. 

I don’t know if woocommerce have all the endpoints to do so. But anyway, it is not so complicated.

 
Posted : 07/16/2024 5:28 pm
(@rajsidhu)
Posts: 34
Eminent Member
Topic starter
 

@ssadvisor So the csv that contains the updated information is always going to be the same file name and location. It just get updated with new stock levels and prices (if they change that is).

What do you think?

 
Posted : 07/16/2024 6:01 pm
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@rajsidhu yes, definitely doable with Make. Try it and if you need help add SSAdvisor as a team member for me to take a look.

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 07/16/2024 10:47 pm
(@rajsidhu)
Posts: 34
Eminent Member
Topic starter
 

@ssadvisor @admin How would i start to create this automation, Can you advise please?

 
Posted : 07/17/2024 9:18 am
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@rajsidhu start here https://learnwithhasan.com/no-code-ai-system-topic-research/

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 07/17/2024 12:15 pm
(@rajsidhu)
Posts: 34
Eminent Member
Topic starter
 

@ssadvisor @admin not sure how this will work for me.

I want to create an automation that will update prices and stock for products in my Woocommerce store.

 
Posted : 07/17/2024 1:48 pm
Hasan Aboul Hasan
(@admin)
Posts: 1208
Member Admin
 

Friend, sorry, but how can we help here?

you can use Make to do this with no code, try it, and we will help. 

 
Posted : 07/18/2024 2:23 pm
(@husein)
Posts: 464
Member Moderator
 

@rajsidhu Try building the foundation yourself and if you faced problems we can help you in this thread.

 
Posted : 07/19/2024 7:49 am
Share: