• Resolved bbirchmeier

    (@bbirchmeier)


    Hello!

    For my shop I need to have all items in one category (KMC Product) to not have an Add To Cart Button when I am logged in. Below is the code I used to do that:

    function kmc_buy_buttons(){
    
    $current_user = wp_get_current_user();
        /**
         * @example Safe usage: $current_user = wp_get_current_user();
         * if ( !($current_user instanceof WP_User) )
         *     return;
         */
    
       $product = get_product();
       if ($current_user->ID >= 3){
    
       if ( has_term('kmc-product', 'product_cat') ){
           // removing the purchase buttons
    
           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 );
    
           remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
    
           remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
    
           remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
    
           remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
    
           }
    
       }
    
    }
    
    add_action( 'wp', 'kmc_buy_buttons' );

    However, there is one item in the shop loop that is in the KEO Product category. It appears in that loop because the page lists all Dovetail HSS products, which that item is a part of. The item also doesn’t have an Add to Cart button, though it should.

    https://www.keocutters.com/product-category/milling-cutters/shank-type/dovetail-cutters/45-single-angle/hss-45-single-angle/page/2/

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Keep add to cart button on certain category in shop loop’ is closed to new replies.