Understanding JSON Booking Structure [MyTicket Events Plugin]

All bookings and seat, zone reservations of MyTicket Events plugin are store in JSON format, we call it reservation object further in text.

Reservation object is linked with the product ID the one that is provided under the WordPress block of Hall Layout pane as shown in the image below.

Defining hall layout product ID under MyTicket Events plugin

In order to retrieve reservation linked to the product ID, for example, 19993, use the following structure.

$reservations = get_option('myticket_19993',[]);

To store existing or modified reservations data structure use the following code.

update_option("myticket_19993", json_encode($reservations));

Please note that you are not restricted to call these lines of codes within WordPress plugin.

You can create a standalone solution to manipulate reservation object independently of MyTicket Events plugin, for example, by creating a custom plugin.

You can release booked seats or mark free seats as booked. However, this by itself will not generate a new order and a PDF ticket. To generate PDF tickets that are linked with WooCommerce order, please refer to WooCommerce API.

Reservation Object Example

{
  "69_0z69": {
    "zone_id": "69",
    "zone_text": "NE",
    "ticket_id": "0z69",
    "ticket_text": "1",
    "ticket_row": "NE",
    "ticket_price": "",
    "cfs": [
      {
        "id": "cf1",
        "index": "1",
        "label": "Gate",
        "value": ""
      }
    ],
    "type": 3,
    "bg": "",
    "cf1": "",
    "tns": "",
    "tws": "50",
    "price": "",
    "title": "NE",
    "height": "100",
    "user": "cFguk",
    "time": 1637328358
  },
  "14_167z14": {
    "zone_id": "14",
    "zone_text": "N8",
    "ticket_id": "167z14",
    "ticket_text": "1"
  .......

In the code example above you can see a JSON object. As described in the previous section such objects can be retrieved in the following way where 19993 is your custom product ID.

$reservations = get_option('myticket_19993',[]);

As you can see reservations are stored in key-value object format where each reserved ticket is represented as another independent object stored under the key with the following structure, zoneID_ticketID, or under the following keys as represented in the code example above 14_167z14, 69_0z69.

The zone and the ticket ID numbers are assigned based on the index value of the array of the original hall layout JSON object structure or simply layout object. The example of this structure is provided in the next chapter.

With the following ID numbers 4_167z14, 69_0z69 original information of layout object structure can be retrieved in the following way:

areas[14].seats.points[167]
areas[69].seats.points[0]

Reservation Object Parameters

zone_id - is taken from "areas" array index of layout object > areas.
zone_text - user defined zone textual description.
ticket_id - is taken from "points" array index of layout object > areas > seats > points.
ticket_text - user defined ticket number or other textual information.
ticket_row - user defined ticket row or other textual information.
ticket_price - user defined ticket price. If left empty general woocommerce product price is taken.
cfs - custom field structure object.
type - ticket reservation state. 
bg - link to zone background image.
cf1 - custom defined field example. If more fields defined will be cf1, cf2, cf3, etc.
tns - total number without seats. Used to define fan zones without tickets.
tws - total number wit seats.
price - user defined custom ticket price.
title - same as zone_text.
user - random string used as user ID during checkout process.
time - server time when booking was performed.

One of the most important parameters of reservation object is the type parameter and it can have the following states:

  • When the type parameter equals to 1, this means that there is an intention to buy the ticket, however, it is not reserved and other users are allowed to book the ticket.
  • When the type parameter equals to 2, this means that the ticket is in the booking process and is reserved for the time as specified under Appearance > Customizer > MyTicket > Checkout > Reservation Time setting. Other users can not book the ticket whet it is marked as reserved. If the reservation time expires earlier than actual booking time then other user can book the same ticket. Please note that with short reservation time setting applied and high booking load this may cause users making payment but not receiving the tickets.
  • When the type parameter equals to 3, this means that the reserved ticket is marked as booked and successfully paid. With this state the ticket object will be kept forever in the reservation object.

Layout Object Example

{
  "areas": [
    ........
    {
      "type": "polygon",
      "seats": {
        "bg": "",
        "tns": "",
        "tws": "3",
        "price": "",
        "title": "K9",
        "height": 51,
        "points": [
          {
            "i": true,
            "p": "",
            "r": "0",
            "t": "text value",
            "x": -143.40716417910448,
            "y": 7.713134328358209
          },
          {  
            "i": true,
            "p": "",
            "r": "0",
            "t": 2,
            "x": -207.68328358208956,
            "y": 7.427462686567164
          },
          {
            "i": true,
            "p": "",
            "r": "0",
            "t": "1",
            "x": -271.95940298507463,
            "y": 7.141791044776119
          }
        ]
      },
      "coords": {
        "points": [
          {
            "x": 145,
            "y": 291
          },
          {
            "x": 685,
            "y": 301
          },
          {
            "x": 687,
            "y": 337
          },
          {
            "x": 3,
            "y": 354
          },
          {
            "x": 1,
            "y": 285
          }
        ],
        "isOpened": false
      },
      "attributes": {
        "id": "GvMENu",
        "href": "",
        "points": []
      }
    },
    {
      "type": "polygon",
      "seats": {
        "title": "Decks",
        "tws": "5",
        "tns": "",
        "price": "",
        "bg": "",
        "points": [
          {
            "i": true,
            "x": 78.438,
            "y": 13.526,
            "r": "",
            "t": "",
            "p": ""
          },
          {
            "i": true,
            "x": 39.474,
            "y": 7.741,
            "r": "",
            "t": "",
            "p": ""
          },
          {
            "i": true,
            "x": 1.02,
            "y": 1.446,
            "r": "",
            "t": "test",
            "p": ""
          },
          {
            "i": true,
            "x": -38.964,
            "y": -3.147,
            "r": "",
            "t": "",
            "p": ""
          },
          {
            "i": true,
            "x": -79.459,
            "y": -10.123,
            "r": "",
            "t": "",
            "p": ""
          },
          {
            "i": true,
            "x": -41.686,
            "y": -11.995,
            "r": "",
            "t": "",
            "p": ""
          },
          {
            "i": true,
            "x": 75.716,
            "y": 32.753,
            "r": "",
            "t": "",
            "p": ""
          }
        ],
        "height": 77
      },
      "coords": {
        "points": [
          {
            "x": 100,
            "y": 86
          },
          {
            "x": 326,
            "y": 111
          },
          {
            "x": 303,
            "y": 173
          },
          {
            "x": 119,
            "y": 152
          }
        ],
        "isOpened": false,
        "points_rel": [
          {
            "x": -112,
            "y": -44.5
          },
          {
            "x": 114,
            "y": -19.5
          },
          {
            "x": 91,
            "y": 42.5
          },
          {
            "x": -93,
            "y": 21.5
          }
        ]
      },
      "attributes": {
        "id": "fJzbLW",
        "href": "",
        "points": []
      }
    }
  ],
  "img": "https://cdn.kenzap.com/myticket/1507.jpeg?1635879658316",
  "img_width": 1052,
  "cfs": []
}

Was this article helpful?