Home ยป Shopify Order Metadata
Metadata

Shopify Order Metadata

 

How to Add Metadata to existing Order

Metadata: You’d be forgiven for thinking you couldn’t as the docs only mention Product meta and Shop meta.

You can add metadata to an existing order that was created through the normal order flow (or an admin order) and not the API.

This Stackoverflow answer pointed me in the right direction. My example is in PHP but you get the idea. Works perfectly;

$orderMetaJson = array(
	"metafield" => array(
		"namespace" => "custom_fields",
		"key" => "my_meta_key",
		"value" => "my_meta_value",
		"value_type" => "string"
	)
);

$json = json_encode($orderMetaJson);

$requestUrl = 'https://[email protected]/admin/orders/' . $order->id . '/metafields.json';

$ch = curl_init($requestUrl);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		'Content-Type: application/json',
		'Content-Length: ' . strlen($json))
);

$curlResult = curl_exec($ch);

curl_close($ch);