Store Shortened IP Addresses and No Browser Details on Orders
Shortens the customer IP address saved with each new WooCommerce order and removes the stored browser user agent, keeping order records leaner on personal data.
Opens WPIDE on
Code
add_action( 'woocommerce_before_order_object_save', function ( $order ) {
if ( ! is_a( $order, 'WC_Order' ) || is_a( $order, 'WC_Order_Refund' ) ) {
return;
}
$ip = $order->get_customer_ip_address( 'edit' );
if ( $ip && wp_privacy_anonymize_ip( $ip ) !== $ip ) {
$order->set_customer_ip_address( wp_privacy_anonymize_ip( $ip ) );
}
if ( $order->get_customer_user_agent( 'edit' ) ) {
$order->set_customer_user_agent( '' );
}
} );
Notes
Fraud prevention and payment plugins may read the full IP during checkout before it is saved; check your fraud tools still work.
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.