Support » Plugin: WooCommerce » How to remove add to cart in specific category shop page and product page.

  • Resolved Arlex

    (@ax18)


    Good day! badly needed help:(. How to remove add to cart in specific category shop page and product page. I’ve already tried this codes:
    1. 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 );

    2. add_action( ‘woocommerce_after_shop_loop_item_title’, ‘hide_loop_product_prices’, 1 );
    function hide_loop_product_prices(){
    global $product;

    if( is_product_category(‘appliances’) || has_term( ‘appliances’, ‘product_cat’, $product->get_id() ) ){

    // Hide add-to-cart button
    remove_action(‘woocommerce_after_shop_loop_item’,’woocommerce_template_loop_add_to_cart’, 30 );

    }
    else
    {
    add_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 30 );
    add_action(‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 30 );
    }

    }

    3. add_action( ‘woocommerce_after_shop_loop_item’, ‘remove_add_to_cart_buttons’, 1 );

    function remove_add_to_cart_buttons() {
    if( has_term( array(‘appliances’,’home-appliances’,’refrigerators’)) || is_shop()) {
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’);
    }
    }

    but still showing add-to-cart buttons in shop/related page. I’ve placed the codes in function.php using my Astra child theme.. Any help really appreciated. Thank you in advance!

    • This topic was modified 4 months, 2 weeks ago by Arlex.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.