Last week we released version 2.4.0 of WooCommerce URL Coupons, which adds support for importing coupon URL data.
Our URL Coupons documentation has a guide to how importing should work, but we’ll go over it in a bit more detail in this quick tutorial. You’ll need to have both URL Coupons (v2.4.0+) and Customer / Coupon / Order CSV Import (v3.1.0+) installed and activated already.
Building the Import File
To import URL coupons, you’ll first need to set up your coupon CSV. The CSV Import documentation covers what data is accepted for coupons, and there’s also a sample CSV file you can download as a start point if desired.
To add URL Coupons data, you’ll need some additional columns in your CSV file. Let’s go through the 5 possible columns, and what data you can add for each.
Remember, since CSV Import uses a column mapper, the name of the column doesn’t much matter. However, if you use these names, it will automatically detect the right mapping to apply, but you can also set it up manually.
This column should contain the slug for the coupon URL. This should not be a full URL, just the slug — for example:
Be sure to pay attention to whether or not you add a trailing slash, as
coupon/thanks will behave differently. You can learn more about this in the plugin documentation.
This column should include one integer value: the ID of the content to which the coupon should redirect. This could be a page / post ID, such as the ID of your cart page. However, it could also be a taxonomy ID, such as the ID of a blog post category, product category, or product tag. Using a taxonomy ID will let you redirect to that category or tag’s archive page.
For example, if I want to redirect to the “Clothing” product category archive, I can use the term ID for that category.
If you want to redirect to anything that’s not a page, you must set the “redirect type” column as well.
This column should have a string to represent the post or taxonomy type for the coupon redirect. This defaults to page, but if your redirect ID is for a product, product_cat, product_tag or other content type, you must set this. The accepted values are:
This column should contain a comma-separated list of product IDs (not SKUs) that should be added to the cart when this coupon is used. While the core coupon restrictions are based on SKUs, URL coupons requires you to use IDs for the products you want added to the cart. This can be blank, have one integer, or multiple integers (IDs) separated by a comma.
A quick note: this won’t apply to most of you, but if you manually build CSV files, just ensure comma-separted columns are automatically wrapped in quotes so the comma isn’t used as a delimiter automatically. Excel, Google Drive, and other programs do this automatically, but for the devs who may use a text file or CLI export, just don’t forget this
This is an easy column — enter “yes” or “no”, “yes” will ensure the coupon is saved in the session and defers applying until the cart meets its requirements. If this is no, “Defer apply” will be disabled, so the cart has to immediately meet requirements for the coupon to be added.
Once you have your CSV file built properly, you can import this coupon data.
Mapping Field Data
When both plugins are active, you’ll see new field options for mapping in the CSV Import column mapper. This will let you map your columns to the right URL Coupons fields in case they don’t map automatically.
Set up your import file options, and when you’ve done so, you’ll map your coupon columns. Here’s a very simple example of a coupon merge / update I’m going to do to add URL Coupons fields to an existing code. I’ve mapped my URL Coupons data to my import file, ensuring that my product IDs and redirect ID / type is set up properly.
Notice that my redirect type is a product category. The ID is for the term ID — in this case my “Music” product category. When I’ve imported this data, the plugin will use both the type and the ID to properly set up your redirect.
There you have it! This lets you easily create new URL Coupons in bulk, or update existing coupons to use URL Coupons options.