how to update your e-Commerce catalog
from a csv file or a remote url
WooCommerce is a fantastic open source solution and the right choice if you're looking for a quick and easy way to open a new e-commerce in a couple of days of work. All of that with just a little or no coding experience.
Setting up your e-commerce with WordPress and WooCommerce can be really smooth, just selecting a preferred layout from tons of free WordPress themes and plugins designed for WooCommerce. The hard work will starts when you need to load thousands of products with their descriptions, prices, sizes and stock quantities. Fortunately, also in this case, WooCommerce can help with its FREE built-in tool: "Import product from CSV"
WooCommerce > Product > Import
This import tool allows you to map fields in a csv file (one product per row) with internal WooCommerce variables and then load or update data if product with same SKU (Stock Keeping Unit) already exists in the catalog. The "mapping" process is even stored into the database, so it can be reused for next import job.
Unfortunately, there is no way to schedule the loading job, at least for free, so all the task has to be managed and run manually every time you need to update your catalog or add additional products in a batch mode.
Of course, there are several plugins you can find and purchase to solve this problem, but this will be yet another plugin where you won't have a complete control of your process.
Here we have the solution with the following PHP code snippet that you could easily adapt to your needs.
1) Our simple PHP script has to be created in a subdirectory under your Wordpress base directory (for example /var/www/html/wordpress/digitalBooster-scripts).
2) First of all we need to to initialize the Wordpress environment calling wp-load.php . In order to do that insert next code snippet at the top of your file.
The code will automatically search for WordPress Base directory and initialize the environment.
3) Here we suppose to feed our e-commerce catalog from a remote csv file.
Our file is a csv with a semicolon as field separator and the product's SKU at first column, price at 17th column ( $price = $s), etc., but of course this must be adapted to your file format.
The following WooCommerce core functions allow you to retrieve product by SKU.
In our really common scenario a Stock Keeping Unit (SKU) has to be stored and used as unique key for any product in your catalog.
Then, the updatate of any product property, like: price, sale price and quantity is performed calling the related WooCommerce function:
Data is then saved and the database transaction completed calling $product->save();
That's all folks ! Hope did you enjoy and we proved you that WordPress and WooCommerce can be customized and adapted to your online business with just a few lines of PHP code.
Please don't hesitate to contact Digital Booster as for our professional services to set up or re-design in a few hours your e-Commerce starting from our e-Commerce Toolbox designed for SME and Local Business that need to open quickly and smoothly their new online shop.
Sample of implementations e-Commerce Toolbox could be found here: