Remove add to cart button for a specific user role in WooCommerce
<p>In my virtual store using the Divi theme along with woocommerce I have the two groups of users: end users and my resellers, in the case of my end client would need only appear the “buy” button. Already for my resellers only the “add to order” button (provided by the YITH Request A Quote plugin).
In case the doubt would be on how to remove the add to cart button for the reseller accounts, I know using the code:</p>

<pre><code>remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
</code></pre>

<p>I remove the button from the whole site, but I am trying to use some kind of <code>if</code> to be able to only define a group.
Something like this:</p>

<pre><code>$user = wp_get_current_user();
if ( in_array( 'Revenda', (array) $user-&gt;roles ) ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
</code></pre>

<p>or this:</p>

<pre><code>if( current_user_can('revenda') ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
</code></pre>

<p>I am also trying this code:</p>

<pre><code>function user_filter_addtocart_for_shop_page(){
    $user_role = get_user_role();
    $role_id = get_role('Revenda');
    if($user_role == $role_id){
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    }
}
</code></pre>

<p>Where get_user_role will be displaying from:</p>

<pre><code>function get_user_role() {
    global $current_user;

    $user_roles = $current_user-&gt;roles;
    $user_role = array_shift($user_roles);

    return $user_role;
}
</code></pre>

<p>How can I achieve this?</p>

<p>Thanks</p>