Woocommerce - How to remove the Add to Cart Button

2020-05-29 11:43发布

问题:

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/