What's the best way and location to add php script API in WP-Woocommerce website

Viewed 19

I have data in Json format that comes from ScalablePress API, what's the best way and location to write the php script for these data should it be in the index.php file of the theme or a plugin? (what do you suggest?)

Also how to make a post then append the post to a page in the website then appent the post to Woocommerce products?

$my_post = array(
  'post_title'    => I'll_Replace_WITH_MY_APIData,
  'post_content'  =>  I'll_Replace_WITH_APIData,
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => 'ScalablePress_Products'
);

The API Data example

{
  "type": "Garment",
  "name": "Sweatshirts",
  "products": [
    {
      "name": "Gildan Sweatshirt - Crew",
      "style": "18000",
      "image": {
        "url": "http://www.ooshirts.com/products/5/catalog.jpg",
        "label": "Catalog"
      },
      "id": "gildan-sweatshirt-crew",
      "url": "https://api.scalablepress.com/v2/products/gildan-sweatshirt-crew"
    },
    {
      "name": "Gildan Heavy Sweatshirt",
      "style": "12000",
      "image": {
        "url": "http://www.ooshirts.com/products/6/catalog.jpg",
        "label": "Catalog"
      },
      "id": "gildan-heavy-sweatshirt",
      "url": "https://api.scalablepress.com/v2/products/gildan-heavy-sweatshirt"
    }
  ],
0 Answers
Related