• dfcdev

    (@dfcdev)


    Hello,

    I was just referred to this forum and I am re-posting my inquiry, I would like to disable the “add to cart” functionality on ALL products based on user role, say for instance all users that are “subscribers” should ONLY be allowed to see the product prices and should NOT be able to add products to the cart and place orders.

    I know i would have to add a conditional statement on the “woocommerce.php” file, all I need is the attributes and logical statement, can someone help?

    Also, I would rather hard code this instead of using a plugin as I already have a few hooks implemented on this file (hide prices for non-logged in users).

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    It will take a bit to code this, but I have this: https://conschneider.de/mini-plugin-disable-woocommerce-prices-add-cart-visitors/ – maybe it is helpful for you as a starting point.

    Thread Starter dfcdev

    (@dfcdev)

    thanks Con! however I already have this functionality hard-coded and implemented onto my child theme see below:

    // * BEGIN Hide prices

    add_action(‘after_setup_theme’,’activate_filter’) ;
    function activate_filter(){
    add_filter(‘woocommerce_get_price_html’, ‘show_price_logged’);
    }
    function show_price_logged($price){
    if(is_user_logged_in() ){
    return $price;
    }
    else
    {

    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’ );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 );
    return ‘Login for Pricing‘;
    remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 10 );

    }
    }
    // * END Hide prices

    I basically just need to hide all add to cart functionality to certain users can someone else take a stab at this and help me hard code this?

    Mina

    (@purpleberryservices)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘disable “add to cart” based on user role’ is closed to new replies.