Link of a JSON parameter to a product in Woocommerce

3

I have a JSON that returns me a list with some flight data:

  "programa": "multiplus",
  "qtdOpcoesIda": 50,
  "qtdOpcoesVolta": 50,
  "menorTarifa": {
    "pontos": 15000,
    "dinheiro": 767.8
  },
  "taxaEmbarque": {
    "POA": 29.9,
    "FLN": 29.9
  },
  "passagens": [
    {
      "pontos": 23000,
      "dinheiro": 738.9,
      "opcoesIda": [
        {  

I am printing this data on a table with "SELECT FLIGHT" buttons (not yet referenced, because I packaged it) for each flight separately. How would I make these buttons use the parameters "program" and "points" of each flight to search for products in the woocommerce that had as category the program, and the minimum points of the result?

I'll be happy if you can help ...

    
asked by anonymous 22.03.2017 / 11:00

1 answer

1

If I understand correctly, you need to access the properties of this JSON, right? Use json_decode() to transform into an object:

$json = '{ "programa": "multiplus", ... }';
$objeto = json_decode( $json );

echo $objeto->programa; // 'multiplus'
echo $objeto->menorTarifa->pontos; // '15000'
echo $objeto->passagens[0]->pontos; // '23000'
    
22.03.2017 / 12:51