# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Requires: WooCommerce
- Tags: woocommerce, ip-address, gdpr
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-woo-mask-order-ip/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Store Shortened IP Addresses and No Browser Details on Orders" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
