Add Custom Order Fields to WooCommerce Privacy Exports
Includes extra checkout fields you store on orders (such as a VAT number or delivery notes) in the order section of personal data exports.
Opens WPIDE on
Code
// Order meta key => label in the export.
$wpide_woo_export_meta = array(
'_billing_vat_number' => 'VAT number',
'_delivery_notes' => 'Delivery notes',
);
add_filter( 'woocommerce_privacy_export_order_personal_data_props', function ( $props ) use ( $wpide_woo_export_meta ) {
foreach ( $wpide_woo_export_meta as $key => $label ) {
$props[ 'wpide_meta_' . $key ] = $label;
}
return $props;
} );
add_filter( 'woocommerce_privacy_export_order_personal_data_prop', function ( $value, $prop, $order ) use ( $wpide_woo_export_meta ) {
if ( 0 !== strpos( $prop, 'wpide_meta_' ) || ! is_a( $order, 'WC_Order' ) ) {
return $value;
}
$key = substr( $prop, strlen( 'wpide_meta_' ) );
return isset( $wpide_woo_export_meta[ $key ] ) ? (string) $order->get_meta( $key ) : $value;
}, 10, 3 );
Notes
Use the order meta keys your checkout field plugin saves; keys starting with an underscore are fine.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.