Assign user role by text field in WordPress (Woocommerce) [closed]

Here is the code: function ur_update_role( $valid_form_data, $form_id, $user_id ) { global $table_prefix; $assign_roles_list = array(); if( isset( $valid_form_data[‘billing_ie’]) && !empty( $valid_form_data[‘billing_ie’]->value ) ) { array_push( $assign_roles_list, ‘ie’ ); } if ( ! empty( $assign_roles_list ) ) { // Re-ordering roles according to priority. $user_roles_list = ur_get_default_admin_roles(); foreach ( $user_roles_list as $key => $value ) … Read more

Restrict product tags archive to certain users

You could setup a redirect at the top of the archive page template for users that don’t match your criteria, something like: $user = wp_get_current_user(); $allowed = array( ‘editor’, ‘administrator’ ); $redirect_url=”https://url-to-redirect-to”; if ( ! $user || ! array_intersect( $allowed, $user->roles ) ) { wp_safe_redirect( $redirect_url, 401 ); exit; } The check for $allowed and … Read more