-4

I'd like to disable checkout based on user roles. For example I'd have two roles; Validated User and Invalidated User. Upon registration users will be Invalidated by default until manually moved to the Validated User role. I'd like the Invalidated users to be able to view and add to cart, but unable to checkout.

BONUS: I'd also like the ability to control the behavior when an invalidated user navigates to check out.

closed as off-topic by EAMann Aug 9 '16 at 21:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • You might want to ask this at the WooCommerce forums - this site is for WordPress specific (not plugin) development. Feel free to take our tour to learn more. – Tim Malone Aug 8 '16 at 23:06
2

Woocommerce is considered off-topic here but as a general answer, it is considered best practice to check against capabilities instead of roles

In WP, this is done like that:

add_action('init', 'wpse_capability_check');  // hooked on 'init' but depends on your actual code logic
function wpse_capability_check(){

  // you should check on a capability that only validated user have
  if( current_user_can( 'validated_user_cap' ) {
    // DO STUFF HERE FOR VALIDATED USERS
  }

  // you should check on a capability that only invalidated user have
  if( current_user_can( 'invalidated_user_cap' ) {
    // DO STUFF HERE FOR INVALIDATED USERS
  }

}

check out https://codex.wordpress.org/Function_Reference/add_cap to know how to add capabilites to roles

This doesn't mean you can't add new roles with your custom cap, but your logic should depend on capability and not roles

BONUS: same logic applies here, you check on the user capability when the checkout process is triggered. You might have another check function hooked on that process

Not the answer you're looking for? Browse other questions tagged or ask your own question.