Woocommerce - How to remove the Add to Cart Button on product listing

允我心安 提交于 2019-12-03 14:14:49

问题


I'm wanting to remove the Add to Cart Button on the product listing pages. The only place I want it to appear is the individual product page. Can anyone suggest on where I can find to remove this? I haven't been able to get any help from the documentation.

At the moment the button appears under every listing.


回答1:


I don't know how to do it from WooCommerce but with following code it is possible, just make sure that these PHP code should execute, so, put it at suitable place in PHP file where some PHP codes are executing, best place would be any wordpress plugin's base file, be careful while updating that plugin as these code will get lost after updating.

add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );

function remove_add_to_cart_buttons() {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}



回答2:


You can remove the add to cart button from product pages by adding this in woocommerce.php (located wp-content/plugins/woocommerce)

function Wp() {
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');
return WooCommerce::instance();
}

After adding this code, reload the page and you will see that the button has been hidden.

You can also remove the add to cart button from specific Product pages using this code in functions.php (located in the theme folder):

add_filter('woocommerce_is_purchasable', 'wp_specific_product');
function wp_specific_product($purchaseable_product_wp, $product) 
{
return ($product->id == specific_product_id (512) ? false : 
$purchaseable_product_wp);
}

For reference you can see

https://wpitech.com/hide-disable-add-to-cart-button-in-woocommerce-store/




回答3:


We have found the answer by coding a little bit, in wordpress:

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

here: https://www.igniweb.com/remove-add-to-cart-button-wordpress/



来源:https://stackoverflow.com/questions/12135190/woocommerce-how-to-remove-the-add-to-cart-button-on-product-listing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!