Integrate product feed API in Woocommerce [closed]

There is a similar problem to create posts from an API and programmatically generating posts.

Essentially just parse the JSON into an array, grab the fields you need, and create the post/product. You most likely need to pull the images as well.

You should also consider if the post already exists in your database and how/where you want the extra metadata to live like; price, stock, year, hours, etc…

JSON PARSE

$response="{"status":"SUCCESS","message":"Results have been extracted","results":[{"post_title":"1984 AQUASPORT 222 FT W96 YAMAHA","post_name":"1984-aquasport-22-2-ft-w96-ya","post_content":"Nice boat 1984 aquasport 22.2 ft c.c 1996 yamaha 200 hp runs good.","post_category":"By Owner","price":"52000","location":"Miami, FL","stock":"952481","year":"2007","images":["http:\/\/boatexportusa.com\/wp-content\/plugins\/api\/get-image.php?src=fakesrc\/00o0o_7TGyKJXFMp9_600x450.jpg","http:\/\/boatexportusa.com\/wp-content\/plugins\/api\/get-image.php?src=fakesrc\/00o0o_7TGyKJXFMp9_600x450.jpg"],"cond":"new","size":"27\"","make":"SeaRay","model":"S300","hours":"330","propulsion":"Power","addedtime":"2015-03-23"}]}';

// decode the json

$json = json_decode($response, true);

// loop through the results

if( ! empty($json[ 'results' ])) {
    foreach($json[ 'results' ] as $data) {

        // gather data you need, make sure to sanitize it

        $post_data = array(
            'post_title'   => $data[ 'post_title' ],
            'post_name'    => $data[ 'post_name' ],
            'post_content' => $data[ 'post_content' ],
            'post_date'    => date('Y-m-d H:i:s'),
            'post_status'  => 'publish', 
            'post_author'  => 1,
        );

        // create product or post and return the new ID

        $post_id = wp_insert_post($post_data, $wp_error);
    }
}

UPDATE

I would recommend putting this into a plugin. That way you can turn it on or off and keep it separate from your main theme. Use something like WPPB.me to generate a basic plugin.

When the plugin activates, schedule a WP Cron task to run daily.

register_activation_hook(__FILE__, 'my_activation');

function my_activation() {
    wp_schedule_event(time(), 'daily', 'my_daily_event');
}

add_action('my_daily_event', 'do_this_daily');

function do_this_daily() {
    // pull api data every day
}

Since the WP Cron is a fake cron it might be best to hook your API pull in the shutdown hook or avoid cron and trigger it from an admin option page. Either way TechCrunch WP Asynchronous Tasks could help offload the processing power to another task.

Once you’ve pulled the new data you’ll want to figure out a way to uniquely identify the product so you don’t duplicate it in the database. Check to see if it exists and if it does then update it. If not, make a new one.

update_post_meta to set it, WP_Meta_Query to see if it exists. Or check by title:

if (null == get_page_by_title($title) && empty(get_posts(array('name' => $slug)))) 

If it helps, make a custom post type to capture the product data and generate them on a custom page template using a custom query.

Everything outside of what I answered you could google, try it out, and ask new questions when you run into issues.