ADD Custom Partner Field for MyAccount page and change user role to Partner
/****************************************************************************************************/
/* ADD Custom Partner Field for MyAccount page and change user role to Partner */
/****************************************************************************************************/
function wooc_extra_register_fields() {
?>
<p class="form-row form-row-wide">
<label for="reg_partner"><?php _e( 'Partner', 'woocommerce' ); ?> </label>
<input type="text" class="input-text" name="partner" id="reg_partner" value="<?php if ( ! empty( $_POST['partner'] ) ) esc_attr_e( $_POST['partner '] ); ?>" />
</p>
<?php
}
add_action( 'woocommerce_register_form', 'wooc_extra_register_fields' );
// Change the user ROLE based on our custom field
function my_new_customer_data($new_customer_data){
if ( $_POST['partner'] == 'natur512' ){
$new_customer_data['role'] = 'partner';
return $new_customer_data;
}
else{
$new_customer_data['role'] = 'customer';
return $new_customer_data;
}
}
add_filter( 'woocommerce_new_customer_data', 'my_new_customer_data');