Skip to content

Instantly share code, notes, and snippets.

@clifgriffin
Last active November 13, 2023 06:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clifgriffin/697d99bc221739e67065cc953cbb70f7 to your computer and use it in GitHub Desktop.
Save clifgriffin/697d99bc221739e67065cc953cbb70f7 to your computer and use it in GitHub Desktop.
Force WooCommerce to use email address as username when registering new accounts.
<?php
// Do NOT include the opening php tag.
// Place in your theme's functions.php file
add_filter( 'woocommerce_new_customer_data', function( $data ) {
$data['user_login'] = $data['user_email'];
return $data;
} );
@julien-paris
Copy link

Works perfectly well 🙏🏼👍🏼

@roversax
Copy link

Hi, sorry for the rookie Q but where/how do I add this code?
Appreciate your time!

@medinarodel
Copy link

medinarodel commented Aug 13, 2021

Hi, sorry for the rookie Q but where/how do I add this code?
Appreciate your time!

2 options:

  1. WP ADMIN:
  • Appearances > Theme Editor > Theme Functions

  • add the code snippet at the very bottom

  • SAVE

  1. FILE (maybe use FTP)
  • [root/wp folder] > wp-content > themes > [theme name] > functions.php

  • add the code snippet at the very bottom

  • reupload the file.

@matusbossak
Copy link

Hi, sorry for the rookie Q but where/how do I add this code?
Appreciate your time!

2 options:

  1. WP ADMIN:
  • Appearances > Theme Editor > Theme Functions
  • add the code snippet at the very bottom
  • SAVE
  1. FILE (maybe use FTP)
  • [root/wp folder] > wp-content > themes > [theme name] > functions.php
  • add the code snippet at the very bottom
  • reupload the file.

It's not the most rational approach to insert your code directly into the functions.php file. This is because it might be overwritten during theme updates.

Probably the best option is to use a snippet plugin like Code Snippets or WPCode. These plugins allow you to add and manage code snippets easily, without directly modifying theme files.

Alternatively, you can consider adding your code snippets to the functions.php file of a child theme. This way, your customizations are not likely to be affected by theme updates, providing a more stable and update-friendly solution 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment