Link a JSON parameter to a product in Woocommerce

Asked

Viewed 106 times

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 in a table with buttons "SELECT FLIGHT" (still no reference, because I have put in this) for each flight separately. How would I make these buttons use the individual "program" and "points" parameters of each flight to search for products in Woocommerce that have as category the determined program, and minimum points of the result?

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

  • Ack Lay, thank you for adjusting the content properly, was my first interaction here, and I didn’t read the posting guidelines, I was in a hurry. It seems the greeting is unnecessary, right.

1 answer

1


If I understand correctly, you need to access the properties of this JSON, right? Use json_decode() to turn 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'
  • Thank you very much Ricardo, this already gives me a way to my resolution. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.