# Link Past Guest Orders to New Accounts

> When a customer registers, attaches any earlier guest orders placed with the same email address to their new account so they appear in My Account.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, customers, orders, accounts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-link-guest-orders/

## Code

```php
add_action( 'woocommerce_created_customer', function ( $customer_id ) {
    if ( function_exists( 'wc_update_new_customer_past_orders' ) ) {
        wc_update_new_customer_past_orders( $customer_id );
    }
} );
```

## Notes

Runs once per new customer account, using WooCommerce's own linking function.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Link Past Guest Orders to New Accounts" 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/
