V
V
vazar092018-09-23 23:58:31
WooCommerce
vazar09, 2018-09-23 23:58:31

How to get meta data from $order?

Please help, I can't get data from the object.

$meta = $order->get_meta_data();
print_r($meta);

Outputs an array
Array
(
    [0] => WC_Meta_Data Object
        (
            [current_data:protected] => Array
                (
                    [id] => 8126
                    [key] => _billing_checkbox
                    [value] => 
                )

            [data:protected] => Array
                (
                    [id] => 8126
                    [key] => _billing_checkbox
                    [value] => 
                )

        )

    [1] => WC_Meta_Data Object
        (
            [current_data:protected] => Array
                (
                    [id] => 8127
                    [key] => _billing_address_3
                    [value] => Kiev
                )

            [data:protected] => Array
                (
                    [id] => 8127
                    [key] => _billing_address_3
                    [value] => Kiev
                )

        )

    [2] => WC_Meta_Data Object
        (
            [current_data:protected] => Array
                (
                    [id] => 8128
                    [key] => _billing_address_4
                    [value] => 235
                )

            [data:protected] => Array
                (
                    [id] => 8128
                    [key] => _billing_address_4
                    [value] => 235
                )

        )

    [3] => WC_Meta_Data Object
        (
            [current_data:protected] => Array
                (
                    [id] => 8129
                    [key] => _billing_address_5
                    [value] => 04114
                )

            [data:protected] => Array
                (
                    [id] => 8129
                    [key] => _billing_address_5
                    [value] => 04114
                )

        )

    [4] => WC_Meta_Data Object
        (
            [current_data:protected] => Array
                (
                    [id] => 8130
                    [key] => _billing_address_6
                    [value] => 04114
                )

            [data:protected] => Array
                (
                    [id] => 8130
                    [key] => _billing_address_6
                    [value] => 04114
                )

        )

    [5] => WC_Meta_Data Object
        (
            [current_data:protected] => Array
                (
                    [id] => 8131
                    [key] => _billing_checkbox2
                    [value] => 
                )

            [data:protected] => Array
                (
                    [id] => 8131
                    [key] => _billing_checkbox2
                    [value] => 
                )

        )

    [6] => WC_Meta_Data Object
        (
            [current_data:protected] => Array
                (
                    [id] => 8132
                    [key] => _billing_payment
                    [value] => 
                )

            [data:protected] => Array
                (
                    [id] => 8132
                    [key] => _billing_payment
                    [value] => 
                )

        )

)

How to get value from this array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2018-09-24
@pton

The first search query on the name of the class, gives a bunch of links,
for example, see the class code here and see the function

/**
   * Return data changes only.
   *
   * @return array
   */
  public function get_changes() {
    $changes = array();
    foreach ( $this->current_data as $id => $value ) {
      if ( ! array_key_exists( $id, $this->data ) || $value !== $this->data[ $id ] ) {
        $changes[ $id ] = $value;
      }
    }
    return $changes;
  }

which will return you an array of data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question