Populating Order Analysis fields directly.

Populating Order Analysis fields directly.

In Settings>Orders any order meta data item can be mapped to one of the 3 Sage order Analysis fields, by providing the meta key name. However, if you have custom fields that are not included in the order meta, then we have a filter for developers to use to directly populate the Analysis fields.

Add the following code to the website's functions.php (this example inserts the shipping method into Analysis 2)

add_filter('woosage_get_analysis_field', 'woosage_get_analysis_field', 10, 4);

function woosage_get_analysis_field($value, $order, $field_number, $meta_key) {

     // Return the shipping method title for analysis field 2
     if ($field_number === 2) {
          $value = $order->get_shipping_method();
     }

     return $value;

}

Replace the value of the field_number (2) with the Analysis field you wish to populate (1, 2 or 3) and set the value of $value to retrieve the data item you want to populate the Analysis field with using the relevant function.