Store only a shortened IP address with each new WooCommerce order, like 203.0.113.0 instead of 203.0.113.42.
add_action( 'woocommerce_new_order', function ( int $order_id, $order = null ): void {
$order = $order instanceof WC_Order ? $order : wc_get_order( $order_id );
if ( ! $order ) {
return;
}
$ip = $order->get_customer_ip_address();
if ( '' === $ip ) {
return;
}
$anonymous = wp_privacy_anonymize_ip( $ip );
if ( $anonymous !== $ip ) {
$order->set_customer_ip_address( $anonymous );
$order->save();
}
}, 10, 2 );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
WooCommerce saves the customer’s full IP address with every order and keeps it indefinitely. A shortened address is still useful for spotting the country or obvious fraud, while being much less personal.
woocommerce_new_order runs once when an order is created, for both the classic and block checkouts. The snippet reads the IP address, shortens it with wp_privacy_anonymize_ip() (the last part of an IPv4 address becomes 0, and IPv6 addresses are cut to the first 3 groups) and saves the order.
Works with both order storage options, HPOS and posts.
Place a test order and open it in WooCommerce → Orders. The customer IP should end in .0.