Add Calculated Field (For Order)

Let’s create an empty custom field:

1. Open section “Setup fields”

2. Open section “Common”

3. Click button “Add Field”

4. Type  custom meta key in textbox (below the select)

5. Fill “Column name”

6. Press button “Confirm”

In my example, I use “custom_address” as meta key on the screenshot

Then I moved the new field from right column to left column (list of exported fields), pressed button “Preview” and got empty column.

Then let’s create a calculating function:

1. Close section “Setup fields”  and open section “Misc Settings”

2. Mark checkbox “Custom PHP code to modify output”

3. Paste following draft function to the textarea

4. Replace FIELD with your meta key (see 1st phase) .

5. Replace $value = “text”; with your code.

Parameters for the hook:

$value is string

$order is WC_Order object

$fieldname is string

In this example, I use meta key  “custom_address” and following code to combine state and postcode.

Then I pressed button “Preview” and got necessary values

If button “Preview” has no effect, there is an error in the code.

So you should mark checkbox “Enable debug output” to see the errors.