Update Permission Account Field
-
Hello there!
What I’m trying to do is quite tricky but I’m hoping you can help.
_____
I’ve added a new forum field to the user account info from my functions called “activation (retail only)”.
_____
If the user fills in this field with a special key, he is granted shopkeeper permissions, which is working (kind of).
The problem is when I save the changes, I have to save them twice for it to change the permissions – the first time the change is made but there is no activation, the second time it activates.
_____
I think it might have something to do with applying the update when the button is pressed vs when its already there.
Can you help? Code Below:
add_action( 'woocommerce_edit_account_form', 'my_woocommerce_edit_account_form' ); add_action( 'woocommerce_save_account_details', 'my_woocommerce_save_account_details' ); function my_woocommerce_edit_account_form() { $user_id = get_current_user_id(); $user = get_userdata( $user_id ); if ( !$user ) return; $twitter = get_user_meta( $user_id, 'twitter', true ); $url = $user->user_url; ?> <fieldset> <legend>Activation (Retail Only):</legend> <p>If you're a stockist of the Real Effect, enter your invoicing code here to activate online invoicing.</p> <p class="form-row form-row-thirds"> <label for="StoreID">Activation:</label> <input type="text" name="StoreID" value="<?php echo esc_attr( $user->StoreID ); ?>" class="input-text" /> </p> </fieldset> <?php } ?> <?php add_action( 'profile_update', 'my_profile_update', 10, 2 ); ?> <?php function my_profile_update( $user_info ){ $user_info = get_userdata( $user_info ); if ( $user_info->StoreID === 'activatestore5879' ){ $user_info->set_role( 'shopkeeper' ); } } ?> <?php function my_woocommerce_save_account_details( $user_id ) { update_user_meta( $user_id, 'StoreID', htmlentities( $_POST[ 'StoreID' ] ) ); }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Update Permission Account Field’ is closed to new replies.