How can I remove the ‘Add to Cart’ button based on user roles?

// REMOVE ADD TO CART BUTTON FOR ADMIN USERS
add_action('wp_loaded', 'wpsc_check_user_role');

function wpsc_check_user_role() {
    $current_user = wp_get_current_user();

    if (!empty($current_user->roles) && $current_user->roles[0] === 'administrator') {
        add_filter('woocommerce_is_purchasable', '__return_false');
    }
}

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This