• Resolved raydelta

    (@raydelta)


    Hi

    I have a role called “Restricted” and I want to ensure that this role is not allowed to purchase on our website, restricting access to checkout or stopping them adding to cart. How can I do this?

    Guests / not logged in must not be affected.

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter raydelta

    (@raydelta)

    As an idea, is there a way to immediately show the user with “restricted” role a blank page saying “your account has been disabled” ?

    Plugin Author Caseproof

    (@caseproof)

    Hi @raydelta

    You could add the code snippet below at the end of your theme’s functions.php file to redirect users with Restricted role from checkout page:

    add_action( 'template_redirect', function () {
    	$user = wp_get_current_user();
    	if ( is_page( 'checkout' ) && is_user_logged_in() && in_array( 'restricted', (array) $user->roles ) ) {
    		$redirect = 'https://your-domain.com/blank-page-with-disabled-message'; // Change this to the correct URL
    		wp_redirect( $redirect );
    		exit;
    	}
    } );

    However, in order to prevent them from adding products to cart, you’ll need to reach out to plugin author that provides “add to cart” functionality and ask them if there’s capability for granting/denying this feature.

    Best

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Restrict Checkout’ is closed to new replies.