WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Remove Add to Cart Buttons from Product Page (31 posts)

  1. samandella
    Member
    Posted 1 year ago #

    How do I remove the add to cart button from the products page and only have it on the individual page of the item I'm selling? I've seen this question asked elsewhere but I don't know which files to access or what code to add/delete. Please could someone help!

    Many thanks

    http://wordpress.org/extend/plugins/woocommerce/

  2. helgatheviking
    Member
    Posted 1 year ago #

    two ways:

    first, put a folder called woocommerce in your theme's folder

    then create a file in this folder /woocommerce/loop/add-to-cart.php and leave the add-to-cart.php blank.

    or in your functions.php

    function remove_loop_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    }
    add_action('init','remove_loop_button');
  3. Derek Allen
    Member
    Posted 1 year ago #

    Hi, I did what you said and it worked but when you click on the product and go into it on the right It has a add to cart button as well. Is there perhaps a script get get rid of this to.

  4. jameskoster
    Member
    Plugin Author

    Posted 1 year ago #

    So you're trying to remove _all_ add to cart buttons? How do people buy things at your store? :-)

    You can remove the add to cart button on the product page by amending the code helga gave you to look like this;

    function remove_loop_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
    add_action('init','remove_loop_button');
  5. Derek Allen
    Member
    Posted 1 year ago #

    Hi, this is for a local bottle store that would like to showcase there products online and offer a free deliver via phone services. I made a sample page of a site a want to do for them.

    http://mytestsite.mavericsa.co.za/

    Thanks the code you gave me is cool now I don't have any add to cart buttons on the site.

    One problem though.

    When I view it on a mobile browser all those buttons show up again. I just need to remove those then it's all cool.

    Would it be possible for you to please help me with this one last thing.

    That will be fantastic.

    Thanks again for you help.

  6. levellsmith
    Member
    Posted 1 year ago #

    I want to add
    if(is_user_logged_in()
    to this.
    So if a user is NOT logged in then the cart button etc will not show.
    Only if user logged in will they show.

    also want to add
    remove_action( 'woo_nav_after', 'wootique_cart_button', 10);
    remove_action( 'woo_nav_after', 'wootique_checkout_button', 20);

    Knowing little to nothing about php coding, I have tried and tried but with no luck.
    Please would somebody help?

  7. fairmountwebdesign
    Member
    Posted 1 year ago #

    Thank you for this information. I also need to remove the "add to cart" from only the product loop page. If the customer clicks on the "add to cart" button, I would like them to be directed to the individual product page. I have the plugin to change the text on the button, I just need to change where it takes them.

    I am new to modifying the code, so if you could explain how to do this step by step with as much detail as you can, I would greatly appreciate it!

    Thank you!

  8. lutzcreativegroup
    Member
    Posted 1 year ago #

    I was able to hide the Add to Cart button with just CSS:

    .woocommerce .products .add_to_cart_button {
    	display: none!important;
    /* Hides the Add to Cart button on the thumbnail pages */
    }
  9. val84
    Member
    Posted 1 year ago #

    Thx It's works for me!

  10. Agence Best Of Site
    Member
    Posted 1 year ago #

    Hello,
    For hidden price and button (add to cart) copy paste this code in function.php themplate.

    function remove_loop_button(){
    if(is_user_logged_in()){}else
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
    add_action('init','remove_loop_button');
    
    add_filter('woocommerce_get_price_html','members_only_price');
    
    function members_only_price($price){
    if(is_user_logged_in() ){
        return $price;
    }
    else return '<a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Login</a> or <a href="'.site_url('/wp-login.php?action=register&redirect_to=' . get_permalink()).'">Register</a> to see price!';
    
    }
  11. Agence Best Of Site
    Member
    Posted 1 year ago #

    For add a link button product add this :
    <a style="clear:both; display:block;" class="button" href="'.get_permalink( $product->id ) .'">Lire plus</a>

    before ";" in the last line
    EX :

    function remove_loop_button(){
    if(is_user_logged_in()){}else
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
    add_action('init','remove_loop_button');
    
    add_filter('woocommerce_get_price_html','members_only_price');
    
    function members_only_price($price){
    if(is_user_logged_in() ){
        return $price;
    }
    else return '<a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Login</a> or <a href="'.site_url('/wp-login.php?action=register&redirect_to=' . get_permalink()).'">Register</a> to see price! <a>id ) .'">Lire plus</a>';
    
    }

    Enjoy ! MIKE

  12. LolaEliz
    Member
    Posted 1 year ago #

    Michael,

    Will one of those codes hide just the add to cart button on the homepage? I don't want to hide the price, I just want to disable the add to cart button. Having it there it reroutes every product on the page to the homepage which is creating an SEO issue of duplicate content. I'd be happy with just making it nofollow. I don't mind it being there, I just don't want the duplicate content issue. Thanks!
    I made the site and know a little about code, but I'm no pro, FYI)

    http://lolacaninecouture.com

  13. Agence Best Of Site
    Member
    Posted 1 year ago #

    Hi LolaEliz,
    In my code they have 2 error i post here the new code :

    function remove_loop_button(){
    if(is_user_logged_in()){}else
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    if(is_user_logged_in()){}else
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
    add_action('init','remove_loop_button');
    
    add_filter('woocommerce_get_price_html','members_only_price');
    
    function members_only_price($price){
    if(is_user_logged_in() ){
        return $price;
    }
    else return '<a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Login</a> or <a href="'.site_url('/wp-login.php?action=register&redirect_to=' . get_permalink()).'">Register</a> to see price!   </br><a class="button linklove" style="display:block;"href="'.get_permalink().'">lire plus</a>';
    
    }

    And with the css hidden the link button on the sigle page( linklove display none !)!

    For you i think it's possible with this code :

    <?php (is_page('home'));
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
     ?>

    Try this !

  14. jimlongo
    Member
    Posted 1 year ago #

    To make the Cart menu conitional, you can use the If Menu plugin to hide the cart menu under certain conditions.
    Also the WooCommerce Menu Cart plugin and remove the Cart menu entirely can work.

  15. LolaEliz
    Member
    Posted 1 year ago #

    Thanks Guys!

    I don't think If Menu works with my theme. I went to the menu section after installing and activating it and there was no indication that the plugin was there. Plus, I don't think it will solve the issue.

    I think maybe I wasn't clear. It's not the cart in the navigation menu that I want to remove -- unless removing it from the navigation bar removes it from each item on the home page.

    On my homepage, each product is displayed, I guess on a loop because I didn't put them there. Each as an "add to cart" button and a "View Products" button. The "add to cart" returns to the homepage -- not to the product page and it adds nothing to the cart -- so I end up with 30-some duplicate pages of the home page and google doesn't like that.

    Michael --

    I'm a novice. Where do I put this code? (sorry to seem dumb about it.) Also, just to be clear, this will only remove the "add to cart" function from the homepage loop? It will still stay on the individual product page?

    <?php (is_page('home'));
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
     ?>
  16. LolaEliz
    Member
    Posted 1 year ago #

    How about a way to add nofollow to the add to cart function? That sounds like an easier fix. Anyone know how to do that? Thank you!!

  17. Agence Best Of Site
    Member
    Posted 1 year ago #

    LoLaEliz,
    I'm not sure understand you, I'm french and my english is no good !
    But have you a link of the website?
    You want to delete the button "add to cart" just do it?

  18. LolaEliz
    Member
    Posted 1 year ago #

    Hi Michael,

    Here is the link http://LOLAcaninecouture.com

    click "add to cart" -- you will see it returns to the homepage. I want no "add to cart" here, but yes on the individual product page. I want to sell, but I don't want "add to cart" to work from the homepage. Because it can't work there -- every item has variations. You need to go to the product page to order.

    Someone above said to put this code in the functions file. It looks logical, like it will do what I want. I don't know if it needs to be in a special place in that file. Can I just put it as the last item in that file?

    thank you so much!
    Lola

    function remove_loop_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    }
    add_action('init','remove_loop_button');
  19. jimlongo
    Member
    Posted 1 year ago #

    Maybe in the template file if there is one for the homepage you can find the add to cart button and remove it. Look for class="add_btn" or something like an href="/?add-to-cart=nnnn" where nnnn is the product-id,

    But you also need to find a way to add it to the individual product pages, because right now it isn't there.

    I clicked a bunch of add to cart buttons on the home page and there was nothing in my cart.
    And when I go to the product pages I can pick variations but can't find a way to add them to my cart.

  20. LolaEliz
    Member
    Posted 1 year ago #

    If you choose your variations, you get an add to cart button on the products page.

    The ADD TO CART on the homepage is completely functionless. That's why I want to remove it.

    This is the only ADD TO CART code I found in the home file:

    <a class="add_btn" href="<?php echo $_product->add_to_cart_url(); ?>"><?php _e("Add To Cart", 'organicthemes'); ?></a>
    		                	<?php } else { ?>
    		                		<a class="add_btn" href="<?php echo $product->add_to_cart_url(); ?>"><?php _e("Add To Cart", 'organicthemes'); ?></a>

    THANK YOU!!!!
    Lola

  21. LolaEliz
    Member
    Posted 1 year ago #

    (I tried that piece of code someone above mentioned and it crashed things so I took it out.)

  22. LolaEliz
    Member
    Posted 1 year ago #

    Here is the woo commerce add-to-cart php. It's probably not smart to mess with that, but it looks like this is where the loop is set up, and how it's set up:

    <?php
    /**
     * Loop Add to Cart
     *
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     1.6.4
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    global $product;
    ?>
    
    <?php if ( ! $product->is_in_stock() ) : ?>
    
    	<a href="<?php echo apply_filters( 'out_of_stock_add_to_cart_url', get_permalink( $product->id ) ); ?>" class="button"><?php echo apply_filters( 'out_of_stock_add_to_cart_text', __( 'Read More', 'woocommerce' ) ); ?></a>
    
    <?php else : ?>
    
    	<?php
    		$link = array(
    			'url'   => '',
    			'label' => '',
    			'class' => ''
    		);
    
    		$handler = apply_filters( 'woocommerce_add_to_cart_handler', $product->product_type, $product );
    
    		switch ( $handler ) {
    			case "variable" :
    				$link['url'] 	= apply_filters( 'variable_add_to_cart_url', get_permalink( $product->id ) );
    				$link['label'] 	= apply_filters( 'variable_add_to_cart_text', __( 'Select options', 'woocommerce' ) );
    			break;
    			case "grouped" :
    				$link['url'] 	= apply_filters( 'grouped_add_to_cart_url', get_permalink( $product->id ) );
    				$link['label'] 	= apply_filters( 'grouped_add_to_cart_text', __( 'View options', 'woocommerce' ) );
    			break;
    			case "external" :
    				$link['url'] 	= apply_filters( 'external_add_to_cart_url', get_permalink( $product->id ) );
    				$link['label'] 	= apply_filters( 'external_add_to_cart_text', __( 'Read More', 'woocommerce' ) );
    			break;
    			default :
    				if ( $product->is_purchasable() ) {
    					$link['url'] 	= apply_filters( 'add_to_cart_url', esc_url( $product->add_to_cart_url() ) );
    					$link['label'] 	= apply_filters( 'add_to_cart_text', __( 'Add to cart', 'woocommerce' ) );
    					$link['class']  = apply_filters( 'add_to_cart_class', 'add_to_cart_button' );
    				} else {
    					$link['url'] 	= apply_filters( 'not_purchasable_url', get_permalink( $product->id ) );
    					$link['label'] 	= apply_filters( 'not_purchasable_text', __( 'Read More', 'woocommerce' ) );
    				}
    			break;
    		}
    
    		echo apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="%s button product_type_%s">%s</a>', esc_url( $link['url'] ), esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $link['class'] ), esc_attr( $product->product_type ), esc_html( $link['label'] ) ), $product, $link );
    
    	?>
    
    <?php endif; ?>
  23. zone19
    Member
    Posted 1 year ago #

    Free Official WC plugin

    WooCommerce Product Archive Customiser

    Allows you to customise WooCommerce product archives. Change the number of product columns and the number of products displayed per page. Toggle the display of core elements and enable some that are not included in WooCommerce core such as stock levels and product categories.

    http://wordpress.org/plugins/woocommerce-product-archive-customiser/

  24. jimlongo
    Member
    Posted 1 year ago #

    try commenting out or removing that add_btn section on the homepage.
    Without seeing more of the code it's hard to tell if there's more to be removed or not.

  25. LolaEliz
    Member
    Posted 1 year ago #

    Thanks, everyone. I'm giving up on this fix. I don't know enough about altering code to not break the site. (the plugin did not effect the home page, just the "shop" page, which didn't have an add to cart button. I'm guessing the Organicstheme somehow overrides the woocommerce settings.

  26. Inevitableuk
    Member
    Posted 12 months ago #

    I have been looking for a similar solution today, and come across the following (yet to test it) but thought it may be of interest.

    http://www.woothemes.com/products/catalog-visibility-options/

  27. Cie Martire
    Member
    Posted 11 months ago #

    Mickael I [bad language removed] LOVE you!!! I've been looking for this solution for days and I just run into your code. Thank you very much!!!!

  28. TheWelsho
    Member
    Posted 10 months ago #

    @ Helga and James Koster: You people ROCK! These fixes worked an absolute treat. Kudos!

  29. lacheney
    Member
    Posted 9 months ago #

    Hi,

    I wanted to hide the add to cart buttons in Woocommerce so I created a custom plugin and added the following code to it:

    function remove_loop_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
    add_action('init','remove_loop_button');

    It worked, but I changed my mind so I deleted the code from the plugin file and yet the buttons are still gone.

    Since then I have deleted the custom plugin, deleted and reinstalled woo commerce plugin, deleted and reinstalled my theme and restarted my server.

    Nothing has worked.

    Any ideas?

  30. vastusth
    Member
    Posted 8 months ago #

    To change or edit read more text in wooCommerce product loop this might help:

    http://graphicscram.com/cram/woocoomerce-change-read-more-text-in-product-loop/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic