businessdad icon

WooCommerce - Set the customer's role on registration

businessdad | PRO | 11/01/16 10:20:09 PM UTC | 0 ⭐ | 949 👁️ | Never ⏰ | []
PHP |

880 B

|

None

|

0 👍

/

0 👎

/**
 * Change the role assigned to customers created by WooCommerce.
 * This specific example sets the role to "business_customer" when both a company
 * name and a VAT number are passed during the registration.
 * Requested by ‎Johankat Roggen-Backwaren Nielsen.
 *
 * Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_discount_aelia
 *
 * @param array customer_data The original customer data.
 * @return array The customer data, with the new role to assign to the client.
 *
 * @author Aelia
 * @link https://aelia.co
 * @link https://www.facebook.com/groups/woohelp/permalink/2043265479233230/
 */
add_filter('woocommerce_new_customer_data', function($customer_data) {
  if(!empty($_POST['billing_company']) && !empty($_POST['vat_number'])) {
    $customer_data['role'] = 'business_customer';
  }
  return $customer_data;
}, 10, 1);

Comments