The WooCommerce cart icon in the header is added by default to your site when you install and activate WooCommerce. However, in some cases, you may want to remove the WooCommerce cart icon from the header to simplify the design or layout of your site.
To remove the WooCommerce cart icon from the header, you can use the woocommerce_before_mini_cart
action hook and the remove_action
function. Here’s an example code snippet:
function wpsnippets_remove_woocommerce_cart_icon() {
remove_action( 'woocommerce_before_mini_cart', 'woocommerce_mini_cart', 10 );
}
add_action( 'init', 'wpsnippets_remove_woocommerce_cart_icon' );
In this code snippet, we define a function wpsnippets_remove_woocommerce_cart_icon
that uses the remove_action
function to remove the woocommerce_mini_cart
function from the woocommerce_before_mini_cart
action hook. We hook this function to the init
action, which ensures that it is loaded early enough to remove the cart icon before it is displayed.
You can modify the priority of the remove_action
function to ensure that the cart icon is removed at the appropriate time, and you can use similar code to remove other elements from the WooCommerce shop pages. Additionally, you can modify the HTML and CSS of your site to adjust the layout of the header without the cart icon.