skip to Main Content

I’ve removed Add to Cart button from Shop and Category pages, but how about Related Products section that is below a product page? The code below doesn’t work for that.

function remove_add_to_cart_buttons() {
  if( is_product_category() || is_shop()) { 
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
  }
}
add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 10 );

2

Answers


  1. You could try using custom CSS as below. Put it under Appearance -> Customizer -> Custom CSS under your admin panel.

    .woocommerce ul.products li.product a.button {
        display: none;
    }
    
    Login or Signup to reply.
  2. Here’s the code for the same:

    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 );
    

    The reason being that the ‘Add to Cart’ button is displayed on these two actions.

    function woocommerce_template_single_add_to_cart()
    {
        global $product;
        do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search