Created
April 19, 2017 19:37
-
-
Save beamkiller/486f9137531a814ad01689fe71d80d76 to your computer and use it in GitHub Desktop.
ADD Custom Partner Field for MyAccount page and change user role to Partner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************************************/ | |
/* 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment