Hide 'add to cart' button ONLY on woocommerce shop/category pages

前端 未结 7 640
广开言路
广开言路 2021-01-03 15:56

I want to hide the button on my shop pages, but I would like to show it on other posts and pages.

I\'ve found this code to hide the add to cart button on my whole we

相关标签:
7条回答
  • 2021-01-03 16:57
        add_action('wp','only_add_bierkoerier_in_cart', 'woocommerce_before_cart');  
    
        function only_add_bierkoerier_in_cart() {
    
        foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    
    
        $bierkoerier_in_cart = false;
        $categories = get_categories();
    
        if ( has_term( 'bierkoerier', 'product_cat', $cart_item['product_id'] ) ) {
            $bierkoerier_in_cart = true;
            break;
        } 
        }
    
        if($bierkoerier_in_cart) {  
            wc_print_notice( 'omdat u bierkoerier producten in uw winkelwagen heeft 
        kunt u geen winkelitems toevoegen', 'notice' );
           if(is_shop() || is_product() || is_product_category()) {
             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 );
        }
    }
    }
    
    0 讨论(0)
提交回复
热议问题