.
WORDPRESS PLUGINS ABOUT

Remove All Add to Cart Buttons in WooCommerce

3 minute read, 2 if you're quick

A client of mine required a button that would remove all Add to Cart buttons throughout the site from a single click. They used this for temporarily stopping purchases if their prices needed changing.
This is particularly handy for emergencies!

You might need a button to do this for many reasons, but it is not needed for most sites. That said, here is the code if you wish to have this button.
It is located on the Dashboard page of WordPress, I put it at the top of the page. For the client I also reduced who could press the button, it might be worth using to stop accidental presses!
In this example, it saves your choice in the Options table.

Here is the link to the WordPress documentation for this command HERE.

There are two sections, one removed from the Product page and the other from the Product Category pages.

//Remove button from Product page
add_action( 'woocommerce_single_product_summary', 'replace_single_add_to_cart_button', 1 );
function replace_single_add_to_cart_button() {

	$option = get_option( 'remove_addToCart_buttons' );

	if ( $option == 'ON' ) {
		
		remove_action( 'woocommerce_single_variation','woocommerce_single_variation_add_to_cart_button', 20 );
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
		
	}
	return;
	
}

//Remove button from Category pages
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_default_button', 10, 2 );
function replace_default_button( $button, $product ){
	
	$option = get_option( 'remove_addToCart_buttons' );

	if ( $option == 'ON' )
		return '';

	return $button;
	
}

//Create WordPress Dashboard Widget/Title
function dashboard_widget() {
	
	//WP function to add dashboard widget
	wp_add_dashboard_widget(
		'remove_addToCart_buttons',//Widget ID
		'Remove Add to Cart buttons',//Widget Name/Title
		'function_remove_addToCart_buttons',//Callback function
		'',//Optional callback control
		'',//Optional callback args
		'side',//Optional context: normal, side, column3, column4
		'high'//Optional priority: high, core, low
	);
	
}
add_action('wp_dashboard_setup', 'dashboard_widget');

//WordPress Dashboard Widget/Title Callback function
function function_remove_addToCart_buttons() {
	
	global $current_user;

	wp_get_current_user();
	if ( $current_user->user_login != 'Stuart' )
		$disabled = 'disabled';

	$option = $_POST['erab'];
		
	if ( $option ) {
		
		if ( $option == 'ON' ? $option = 'Off' : $option = 'ON' );

		update_option( 'remove_addToCart_buttons', $option );

	} else {

		if ( ( ! $n  ) OR ( $n == 'Off' ) ) {
			
			$option = 'Off';
			
		} else {
			
			$option = 'ON';
			
		}
		
	}

	if ( $option == 'ON' )
		$css = 'color: white;background-color: red;border-color: red;';
	
	?>
	<p>If turned ON none of the Add to Cart buttons will be displayed!
	<form method="POST" >
		<button name="erab" class="button btn" style="width: 100%; <?=$css?>" value="<?=$option?>" <?=$disabled?> >Currently turned <?=$option?></button>
	</form>	
	<?php

	return;
	
}


^