I used this plugin once for one website and I used this code to achieve similar effect:
/**
- Hides all pricing
*/
add_filter(‘woocommerce_get_price_html’,‘members_only_price’);
function members_only_price($price){
if(is_user_logged_in() ){
return $price;
}
else return ‘’;
}
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 );
function user_autologout(){
if ( is_user_logged_in()) {
$user_id = get_current_user_id();
$approved_status = get_user_meta($user_id, ‘wp-approve-user’, true);
//if the user hasn’t been approved yet by WP Approve User plugin, log them out immediately
if ( empty($approved_status) || $approved_status == 0 ) {
//echo ‘not approved’;
wp_logout_url( get_permalink(woocommerce_get_page_id(‘myaccount’)) . “?approved=false” );
wp_logout();
}
}
}
//add_action(‘init’, ‘user_autologout’);
//add_action(‘woocommerce_before_my_account’, ‘user_autologout’, 2);
remove_action(‘init’, ‘woocommerce_process_registration’);
add_action(‘init’, ‘wp_approve_registration’);
function wp_approve_registration() {
global $woocommerce, $current_user;
if ( ! empty( $_POST['register'] ) ) {
$woocommerce->verify_nonce( 'register' );
// Get fields
$user_email = isset( $_POST['email'] ) ? trim( $_POST['email'] ) : '';
$password = isset( $_POST['password'] ) ? trim( $_POST['password'] ) : '';
$password2 = isset( $_POST['password2'] ) ? trim( $_POST['password2'] ) : '';
$user_email = apply_filters( 'user_registration_email', $user_email );
if ( get_option( 'woocommerce_registration_email_for_username' ) == 'no' ) {
$username = isset( $_POST['username'] ) ? trim( $_POST['username'] ) : '';
$sanitized_user_login = sanitize_user( $username );
// Check the username
if ( $sanitized_user_login == '' ) {
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please enter a username.', 'woocommerce' ) );
} elseif ( ! validate_username( $username ) ) {
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'This username is invalid because it uses illegal characters. Please enter a valid username.', 'woocommerce' ) );
$sanitized_user_login = '';
} elseif ( username_exists( $sanitized_user_login ) ) {
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'This username is already registered, please choose another one.', 'woocommerce' ) );
}
} else {
$username = $user_email;
$sanitized_user_login = sanitize_user( $username );
}
// Check the e-mail address
if ( $user_email == '' ) {
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Please type your e-mail address.', 'woocommerce' ) );
} elseif ( ! is_email( $user_email ) ) {
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'The email address isn’t correct.', 'woocommerce' ) );
$user_email = '';
} elseif ( email_exists( $user_email ) ) {
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'This email is already registered, please choose another one.', 'woocommerce' ) );
}
// Password
if ( ! $password ) $woocommerce->add_error( __( 'Password is required.', 'woocommerce' ) );
if ( ! $password2 ) $woocommerce->add_error( __( 'Re-enter your password.', 'woocommerce' ) );
if ( $password != $password2 ) $woocommerce->add_error( __( 'Passwords do not match.', 'woocommerce' ) );
// Spam trap
if ( ! empty( $_POST['email_2'] ) )
$woocommerce->add_error( __( 'Anti-spam field was filled in.', 'woocommerce' ) );
// More error checking
$reg_errors = new WP_Error();
do_action( 'register_post', $sanitized_user_login, $user_email, $reg_errors );
$reg_errors = apply_filters( 'registration_errors', $reg_errors, $sanitized_user_login, $user_email );
if ( $reg_errors->get_error_code() ) {
$woocommerce->add_error( $reg_errors->get_error_message() );
return;
}
if ( $woocommerce->error_count() == 0 ) {
$new_customer_data = array(
'user_login' => $sanitized_user_login,
'user_pass' => $password,
'user_email' => $user_email,
'role' => 'customer'
);
$user_id = wp_insert_user( apply_filters( 'woocommerce_new_customer_data', $new_customer_data ) );
if ( is_wp_error($user_id) ) {
$woocommerce->add_error( '<strong>' . __( 'ERROR', 'woocommerce' ) . '</strong>: ' . __( 'Couldn’t register you… please contact us if you continue to have problems.', 'woocommerce' ) );
return;
}
// Get user
$current_user = get_user_by( 'id', $user_id );
// Action
do_action( 'woocommerce_created_customer', $user_id );
// send the user a confirmation and their login details
$mailer = $woocommerce->mailer();
$mailer->customer_new_account( $user_id, $password );
/*
// set the WP login cookie
$secure_cookie = is_ssl() ? true : false;
wp_set_auth_cookie($user_id, true, $secure_cookie);
*/
$woocommerce->add_message( 'Registration successful! You will be notified upon approval of your account.', 'woocommerce' ) ;
// Redirect
if ( wp_get_referer() ) {
$redirect = esc_url( wp_get_referer() );
} else {
$redirect = esc_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) );
}
wp_redirect( apply_filters( 'woocommerce_registration_redirect', $redirect ) );
exit;
}
}
}
function registration_message(){
$not_approved_message = “
Send in your registration application today!
All customers can register using the form set out below. Once your details are verified by a member of our admin staff, your account will be activated and you will recieve a notification email.
NOTE: Your account will be held for moderation and you will be unable to login until it is approved.
”;
echo $not_approved_message;
}
add_action(‘woocommerce_before_customer_login_form’, ‘registration_message’, 2);
//Email Notifications
//Content parsing borrowed from: woocommerce/classes/class-wc-email.php
function send_user_approve_email($user_id){
global $woocommerce;
//Instantiate mailer
$mailer = $woocommerce->mailer();
if (!$user_id) return;
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$user_pass = "As specified during registration";
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$subject = apply_filters( 'woocommerce_email_subject_customer_new_account', sprintf( __( 'Your account on %s has been approved!', 'woocommerce'), $blogname ), $user );
$email_heading = "User $user_login has been approved";
// Buffer
ob_start();
// Get mail template
woocommerce_get_template('emails/customer-account-approved.php', array(
'user_login' => $user_login,
'user_pass' => $user_pass,
'blogname' => $blogname,
'email_heading' => $email_heading
));
// Get contents
$message = ob_get_clean();
// Send the mail
woocommerce_mail( $user_email, $subject, $message, $headers = "Content-Type: text/htmlrn", $attachments = "" );
}
add_action(‘wpau_approve’, ‘send_user_approve_email’, 10, 1);
function send_user_unapprove_email($user_id){
return;
}
add_action(‘wpau_unapprove’, ‘send_user_unapprove_email’, 10, 1);