#StackBounty: #php #wordpress #woocommerce #product #code-snippets Remove Add do Cart Button for customers and guests for specifics pro…

Bounty: 50

For Woocommerce, I need a PHP snippet that will hide few products ID’s I will select for guests and customers.

My code attempt:

function dma_restrict_product() {

    $user = wp_get_current_user();
    $user_meta = get_userdata($user->ID);
    $user_roles = $user_meta->roles;
    global $product;

    if( in_array( 'customer', (array) $user_roles ) && ( is_single('3759') ) ) {
        return true;
        add_filter('woocommerce_is_purchasable', 'woocommerce_cloudways_purchasable');
        function woocommerce_cloudways_purchasable($cloudways_purchasable, $product) {
            return ($product->id == 3759 ? false : $cloudways_purchasable);

    } else if( in_array('administrator', (array) $user_roles) ) {
        return true;
    } else {
        return false;

But it doesn’t work as I would like.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.