Search code examples
phpwordpresswoocommerceproductstorefront

Remove "Add To Card" only Home page in WooCommerce


I want to remove "Add To Card" or any other button on home page of WooCommerce Theme but not from product single page.

For example: Home Page: https://demo.woothemes.com/storefront/ Product Single Page: https://demo.woothemes.com/storefront/product/build-your-dslr/

I don't want to show any button on home page under product. Home Page

But I want to show button on product page. enter image description here

I want to do this because i want to force my website visitor to visit product single page.

Which code line will I remove from website > Appearance > Editor?


Solution

  • Try the following:

    add_action( 'woocommerce_after_shop_loop_item', 'remove_loop_add_to_cart_on_home', 1 );
    function remove_loop_add_to_cart_on_home() {
        if( is_front_page() ){
            remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
        }
    }
    

    Code goes in function.php file of your active child theme (or active theme).


    To remove it on shop page too you will have:

    add_action( 'woocommerce_after_shop_loop_item', 'remove_loop_add_to_cart_on_home', 1 );
    function remove_loop_add_to_cart_on_home() {
        if( is_front_page() || is_shop() ){
            remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
        }
    }
    

    Code goes in function.php file of your active child theme (or active theme).

    See Woocommerce conditional tags