This function would generate a unique user login slug:
function my_unique_user_slug( $slug ) {
global $wpdb;
$check_sql = "SELECT user_login FROM $wpdb->users WHERE user_login = %s LIMIT 1";
if ( ! $wpdb->get_var( $wpdb->prepare( $check_sql, $slug ) ) ) {
return $slug;
}
$suffix = 2;
do {
$alt_slug = $slug . $suffix;
$user_slug_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_slug ) );
$suffix++;
} while ( $user_slug_check );
return $alt_slug;
}
It is based on the wp_unique_post_slug()
function, and you can use it like so:
if ( ! empty( $complete_name ) ) {
$slug = sanitize_user( preg_replace( '/\s+/u', '', $complete_name ) );
$new_customer_data['user_login'] = my_unique_user_slug( $slug );
}
Related Posts:
- Including user data in “new user notification email”
- Displaying Logged-In User Name in WordPress Menu
- Edit tag cloud widget number
- How to automatically apply woocommerce product title to all product images alt tags?
- How to get the original price of the product in woocommerce?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- WooCommerce – Customer Order History Pagination
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- The values of custom fields are not available functions.php
- WooCommerce – Display variation custom field value [closed]
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- Woocommerce HTML email option unavailable
- How to add SVG icon above product tab title
- Trigger Woocommerce New User Email
- My Own layout in WooCommerce pages [closed]
- Woocommerce – remove product from category
- Limiting woocommerce line_total decimal length
- How do I display a user’s previous orders as a select box option on a product?
- How do you add customer capability after Woocommerce purchase?
- WooCommerce – Reset quantity input field when variation changes
- get current product name in functions.php
- Image as Sales Badge
- Automatically remove a canceled order in Woocommerce
- Two Different Links for Same Product – WooCommerce [closed]
- How can I apply_filters from inside a function?
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- How can I get the values of my WordPress $wpdb query in Jquery?
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Validation algorithm in checkout field
- My new button is in the wrong place
- php function to display commenter username or login
- Run a code only on theme activation only during first activation
- Fatal error: Call to undefined function register_new_user()
- require_once() if a product in woocommerce contains a tag [closed]
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- Remove item in Checkout
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- woocommerce specific quantities for product
- Personalize checkout text
- CSS change in woo commerce Place Order Text [closed]
- WP All Import / Update stock quantity from multiple XML files
- woocommerce related product title length
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- How do i wrap woocomerce attribute in list?
- Removing files programmatically
- Custom User Registration script only allowing usernames with 16 characters
- Custom Taxonomy Select Menu: Setting default option value?
- Execute PHP code only with specific user role
- Woocommerce order status payment
- Modify WooCommerce used to get all orders in dashboard
- Output product category link from WP_Query
- Woocommerce My acount page
- Woocommerce – Exclude variation attribute on specific variation
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- PHP function for horizontal Woocommerce thumbnails and badges
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- php code for outputting a custom page in my account
- Hide specific shipping methode depending on day and time of day
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- Adding custom field to product category and show it to shop/category shop page
- Hide payment method based on user role AND minimum cart value
- WooCommerce display price before add to cart [closed]
- Remove span tags from WooCommerce Downloads page
- Best way to use variables in multiple functions?
- Display a custom name when the user has no name settle in his account
- Discount in the specific product title using keyword ( Woocoommerce )
- Woocommerce – if selected attribute term equals
- split 1 cart item into instock and back ordered
- Adding product permalink on admin order page throwing error
- Add Product Permalink in woocommerce admin order page
- How to override WooCommerce Order Item Meta with data from Cart?
- Woocommerce textarea format ignored
- Remove generated category and tag class names from woocommerce product & blog listings markup
- WP_Query To Display Product Of Brand On Taxonomy Page
- Woocommerce Add custom “Add to cart button” in single page with tags
- Get Billing Email from WooCommece Checkout and Pass to Fullstory JS
- Add missing alt tag to featured images for “storefront” theme
- Use WP_Query Data In Cookie
- Registration form not registering First and Last name
- Woocommerce Price Text
- How to get the rating value of each comment
- How to add margin underneath woocommerce total price amount -> productpages
- Setting WooCommerce currency programmatically
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- Warning: Attempt to read property “term_id” on int – Woocommerce
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- posts_clauses drop ACF get_field function
- Replace the image of a product with its video in the shop page
- WCFM Custom form
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- Automatically change insurance quantity based on cart total [closed]
- Change WooCommerce Order status from frontend form submitted data
- Add text below WooCommerce short description if metabox value is true