Author: WooThemes
Inheritance: extends WC_Data_Store_WP, implements WC_Object_Data_Store_Interface, implements WC_Abstract_Order_Data_Store_Interface
 /**
  * Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
  *
  * @param WC_Order
  * @param bool $force Force all props to be written even if not changed. This is used during creation.
  * @since 2.7.0
  */
 protected function update_post_meta(&$refund, $force = false)
 {
     parent::update_post_meta($refund, $force);
     $updated_props = array();
     $changed_props = $refund->get_changes();
     $meta_key_to_props = array('_refund_amount' => 'amount', '_refunded_by' => 'refunded_by', '_refund_reason' => 'reason');
     foreach ($meta_key_to_props as $meta_key => $prop) {
         if (!array_key_exists($prop, $changed_props) && !$force) {
             continue;
         }
         $value = $refund->{"get_{$prop}"}('edit');
         if ('' !== $value ? update_post_meta($refund->get_id(), $meta_key, $value) : delete_post_meta($refund->get_id(), $meta_key)) {
             $updated_props[] = $prop;
         }
     }
 }
 /**
  * Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
  *
  * @param WC_Order
  * @param bool $force Force all props to be written even if not changed. This is used during creation.
  * @since 2.7.0
  */
 protected function update_post_meta(&$order, $force = false)
 {
     $updated_props = array();
     $changed_props = $order->get_changes();
     $meta_key_to_props = array('_order_key' => 'order_key', '_customer_user' => 'customer_id', '_payment_method' => 'payment_method', '_payment_method_title' => 'payment_method_title', '_transaction_id' => 'transaction_id', '_customer_ip_address' => 'customer_ip_address', '_customer_user_agent' => 'customer_user_agent', '_created_via' => 'created_via', '_completed_date' => 'date_completed', '_paid_date' => 'date_paid', '_cart_hash' => 'cart_hash');
     foreach ($meta_key_to_props as $meta_key => $prop) {
         if (!array_key_exists($prop, $changed_props) && !$force) {
             continue;
         }
         $value = $order->{"get_{$prop}"}('edit');
         if ('' !== $value ? update_post_meta($order->get_id(), $meta_key, $value) : delete_post_meta($order->get_id(), $meta_key)) {
             $updated_props[] = $prop;
         }
     }
     $address_props = array('billing' => array('_billing_first_name' => 'billing_first_name', '_billing_last_name' => 'billing_last_name', '_billing_company' => 'billing_company', '_billing_address_1' => 'billing_address_1', '_billing_address_2' => 'billing_address_2', '_billing_city' => 'billing_city', '_billing_state' => 'billing_state', '_billing_postcode' => 'billing_postcode', '_billing_country' => 'billing_country', '_billing_email' => 'billing_email', '_billing_phone' => 'billing_phone'), 'shipping' => array('_shipping_first_name' => 'shipping_first_name', '_shipping_last_name' => 'shipping_last_name', '_shipping_company' => 'shipping_company', '_shipping_address_1' => 'shipping_address_1', '_shipping_address_2' => 'shipping_address_2', '_shipping_city' => 'shipping_city', '_shipping_state' => 'shipping_state', '_shipping_postcode' => 'shipping_postcode', '_shipping_country' => 'shipping_country'));
     foreach ($address_props as $props_key => $props) {
         foreach ($props as $meta_key => $prop) {
             $prop_key = substr($prop, 8);
             if (!$force && (!isset($changed_props[$props_key]) || !array_key_exists($prop_key, $changed_props[$props_key]))) {
                 continue;
             }
             $value = $order->{"get_{$prop}"}('edit');
             if ('' !== $value ? update_post_meta($order->get_id(), $meta_key, $value) : delete_post_meta($order->get_id(), $meta_key)) {
                 $updated_props[] = $prop;
                 $updated_props[] = $props_key;
             }
         }
     }
     parent::update_post_meta($order, $force);
     // If address changed, store concatinated version to make searches faster.
     if (in_array('billing', $updated_props) || !metadata_exists('post', $order->get_id(), '_billing_address_index')) {
         update_post_meta($order->get_id(), '_billing_address_index', implode(' ', $order->get_address('billing')));
     }
     if (in_array('shipping', $updated_props) || !metadata_exists('post', $order->get_id(), '_shipping_address_index')) {
         update_post_meta($order->get_id(), '_shipping_address_index', implode(' ', $order->get_address('shipping')));
     }
     // If customer changed, update any downloadable permissions.
     if (in_array('customer_user', $updated_props) || in_array('billing_email', $updated_props)) {
         $data_store = WC_Data_Store::load('customer-download');
         $data_store->update_user_by_order_id($order->get_id(), $order->get_customer_id(), $order->get_billing_email());
     }
 }