WooCommerce REST API – Import products from JSON

I had a task to create a PHP script to import simple and variable products from JSON file using the WooCommerce REST API. Thought it might be worth sharing with others because I couldn’t find much information about products import from JSON using the API.

To make it easier to understand, I created a simple JSON file with one simple product and one variable product that have two product variations. You can get all files from Github repository.

products.json

Getting started

What you need to do is download a PHP wrapper for the WooCommerce REST API. You can download it using composer from https://packagist.org/packages/automattic/woocommerce If you don’t have composer yet, then you can download it from https://getcomposer.org

Setup

Setup for the new WP REST API integration (WooCommerce 2.6 or later):

1. Parse JSON

Convert JSON string to PHP array.

2. Get all product attributes from JSON

We need to get all product attributes names and values from JSON file.

3. Get products and variations from JSON for importing

4. Merge products and product variations

Used to loop through products, then loop through product variations.

5. A simple function to print status message

Import products to WooCommerce using the API

You can find the script on Github repository

My first package for Laravel – Google Safe Browsing Lookup (v4)

I’ve been working on an exciting project, and one of the first task was to integrate Google Safe Browsing into the project. The Safe Browsing APIs (v4) let you check URLs against Google’s constantly updated lists of unsafe web resources. However, I couldn’t find a working package for Laravel 5.4 so I decided to create my own and share it on github and packagist.

Installation

Run the following from the Terminal:

Next, add your new provider to the providers array of config/app.php:

Finally, add aliases to the aliases array of config/app.php:

Preparation

You need to get your API key from Google Safe Browsing API.

Publish the config file.

Set your API key in YOUR-APP/config/google_safe_browsing.php

Usage

More examples

License

The package is licensed under the GPL v3 License.