title: How to read array structure and get certain data in Php
body: <p>I want to get the <strong>product_id,variation_id,and quantity</strong> from this cart array. By the way this cart array was return by woocommerce get_cart function. How do I read this array in Php so I can get the data? I need those 3 data to create an order with it.</p>
  
  <pre><code>public function get_cart(){
              $user_id = 1;
              $key = '_woocommerce_persistent_cart';
              $single = true;
              $carts = get_user_meta($user_id, $key, $single);
              return $carts;
          }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/d4zSM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d4zSM.png" alt="enter image description here"></a></p>
  
  <p>i have customize order creation code below how can i change it?</p>
  
  <pre><code>public function Order_creation()
      {
          if ($_REQUEST['dev']) {
              $address = array(
              'first_name' =&gt; 'Zayle',
              'last_name' =&gt; 'Ong',
              'company' =&gt; 'Timios',
              'email' =&gt; 'Crystalize@hotmail.com',
              'phone' =&gt; '777-777-777-777',
              'address_1' =&gt; '31 Main Street',
              'address_2' =&gt; '',
              'city' =&gt; 'Simei',
              'state' =&gt; 'SG',
              'postcode' =&gt; '520151',
              'country' =&gt; 'Singapore'
              );
              $userid = 1;
              /*
                  * Example product 1 simple
              */
              $pointsEarn = 88;
              $products[] = array(
              "id" =&gt; 9, // id of product
              "variation" =&gt; '', // id of variaton
              "quantity" =&gt; 1
              ) // quantity
              ;
              /*
                  * Example product variation
              */
              $products[] = array(
              "id" =&gt; 76, // id of product
              "variation" =&gt; 97, // id of variaton
              "quantity" =&gt; 2
              ); // quantity
              $products[] = array(
              "id" =&gt; 76, // id of product
              "variation" =&gt; 98, // id of variaton
              "quantity" =&gt; 1
              );
              $redeemedPoints = 100;
              $note = "Test Note";
              } else {
              $address = array(
              'first_name' =&gt; $_POST['first_name'],
              'last_name' =&gt; $_POST['last_name'],
              'company' =&gt; $_POST['company'],
              'email' =&gt; $_POST['email'],
              'phone' =&gt; $_POST['phone'],
              'address_1' =&gt; $_POST['adddress1'],
              'address_2' =&gt; $_POST['adddress2'],
              'city' =&gt; $_POST['city'],
              'state' =&gt; $_POST['state'],
              'postcode' =&gt; $_POST['postcode'],
              'country' =&gt; $_POST['country']
              );
              $userid = $_POST['userid'];
              /*
                  * POST products should be like
                  * array(array("id"=&gt;1,"variation"=&gt;"","quantity"),array("id"=&gt;1,"variation"=&gt;"","quantity"=&gt;1),array("id"=&gt;1,"variation"=&gt;"","quantity"=&gt;3))
              */
              $pointsEarn = $_POST['PointsEarn'];
              $products = $_POST['products'];
              $redeemedPoints = $_POST['redeemedPoints'];
              $note = $_POST['note'];
              if (! $_POST['first_name'] &amp;&amp; ! $_POST['last_name'] &amp;&amp; ! $_POST['email'] &amp;&amp; ! $_POST['adddress1'] &amp; ! $_POST['city']) {
                  return array(
                  "error" =&gt; "Please fill First name, Last Name, Address and City",
                  "orderstatus" =&gt; "error"
                  );
              }
              if (! $userid) {
                  return array(
                  "error" =&gt; "Need to specify a userid",
                  "orderstatus" =&gt; "error"
                  );
              }
              if (! $productid) {
                  return array(
                  "error" =&gt; "Need to specify a product id",
                  "orderstatus" =&gt; "error"
                  );
              }
              if (! $redeemedPoints) {
                  return array(
                  "error" =&gt; "Need to specify points to use",
                  "orderstatus" =&gt; "error"
                  );
              }
          }
  
          $pointsuser = WC_Points_Rewards_Manager::get_users_points($userid);
          if ($pointsuser &gt;= $$redeemedPoints) {
              $order = wc_create_order();
              if (count($products)) {
                  foreach ($products as $key =&gt; $value) {
                      if ($value['variation']) {
                          $product = new WC_Product_Variable($value['id']);
                          $product-&gt;variation_id = $value['variation'];
                          $variation = $product-&gt;get_available_variations();
                          foreach ($variation as $key2 =&gt; $value2) {
                              if ($value2['variation_id'] == $value['variation']) {
                                  $valdata['variation'] = $value2['attributes'];
                              }
                          }
                          $order-&gt;add_product($product, $value['quantity'], $valdata);
                          update_post_meta($value['variation'], "_stock", (get_post_meta($productid, "_stock", true) - $value['quantity']));
                          } else {
                          $product = new WC_Product($value['id']);
                          $order-&gt;add_product($product, $value['quantity']);
                          update_post_meta($value['id'], "_stock", (get_post_meta($productid, "_stock", true) - $value['quantity']));
                      }
                  }
              }
  
              if (! $product-&gt;is_type('variable')) {} else {}
  
              $order-&gt;set_address($address, 'billing');
              $order-&gt;set_address($address, 'shipping');
              $discount_code = str_replace("--userid--", $userid, "wc_points_redemption_--userid--_" . date("d-m-Y") . "_" . rand(0, 99999));
              /*
                  * Create coupon
              */
              $coupon_code = $discount_code; // Code
              $amount = WC_Points_Rewards_Manager::calculate_points_value($redeemedPoints); // Amount
              $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
  
              $coupon = array(
              'post_title' =&gt; $coupon_code,
              'post_content' =&gt; '',
              'post_status' =&gt; 'publish',
              'post_author' =&gt; $userid,
              'post_type' =&gt; 'shop_coupon'
              );
  
              $new_coupon_id = wp_insert_post($coupon);
  
              // Add meta
              update_post_meta($new_coupon_id, 'discount_type', $discount_type);
              update_post_meta($new_coupon_id, 'coupon_amount', $amount);
              update_post_meta($new_coupon_id, 'individual_use', 'no');
              update_post_meta($new_coupon_id, 'product_ids', '');
              update_post_meta($new_coupon_id, 'exclude_product_ids', '');
              update_post_meta($new_coupon_id, 'usage_limit', '1');
              update_post_meta($new_coupon_id, 'expiry_date', '');
              update_post_meta($new_coupon_id, 'apply_before_tax', 'yes');
              update_post_meta($new_coupon_id, 'free_shipping', 'no');
              $order-&gt;add_order_note( $note);
              $order-&gt;add_coupon($discount_code, $amount);
              $order-&gt;calculate_totals();
              $order-&gt;set_total($order-&gt;calculate_totals() - $amount);
              $order-&gt;set_total($amount, 'cart_discount');
              $orderid = new WC_Order($order-&gt;ID);
              $order_id = trim(str_replace('#', '', $order-&gt;get_order_number()));
  
              add_post_meta($order_id, '_payment_method', 'Pending Payment');
              update_post_meta($order_id, '_created_via', 'checkout');
              update_post_meta($order_id, '_customer_user', $userid);
              add_post_meta($order_id, '_payment_method_title', 'Pending Payment');
              update_post_meta($order-&gt;id, '_wc_points_redeemed', $redeemedPoints);
              WC_Points_Rewards_Manager::decrease_points($userid, $redeemedPoints, 'order-redeem', "coupon " . $coupon_code . " used for order " . $order_id, $order_id);
              update_post_meta( $order-&gt;id, '_wc_points_earned', $pointsEarn );
              WC_Points_Rewards_Manager::increase_points( $order-&gt;user_id, $pointsEarn, 'order-placed', null, $order-&gt;id );
              return array(
              "orderid" =&gt; $order_id,
              "points earn" =&gt;$pointsEarn,
              "orderstatus" =&gt; "ok"
              );
              } else {
              return array(
              "error" =&gt; "You do not have enought points",
              "orderstatus" =&gt; "error"
              );
          }
      }
  </code></pre>