Advertisement
businessdad

WooCommerce - Set the customer's role on registration

Nov 1st, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. /**
  2.  * Change the role assigned to customers created by WooCommerce.
  3.  * This specific example sets the role to "business_customer" when both a company
  4.  * name and a VAT number are passed during the registration.
  5.  * Requested by ‎Johankat Roggen-Backwaren Nielsen.
  6.  *
  7.  * Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_discount_aelia
  8.  *
  9.  * @param array customer_data The original customer data.
  10.  * @return array The customer data, with the new role to assign to the client.
  11.  *
  12.  * @author Aelia
  13.  * @link https://aelia.co
  14.  * @link https://www.facebook.com/groups/woohelp/permalink/2043265479233230/
  15.  */
  16. add_filter('woocommerce_new_customer_data', function($customer_data) {
  17.   if(!empty($_POST['billing_company']) && !empty($_POST['vat_number'])) {
  18.     $customer_data['role'] = 'business_customer';
  19.   }
  20.   return $customer_data;
  21. }, 10, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement