Last updated on September 13, 2023

Remove WooCommerce Cart from Divi Menu

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Remove the WooCommerce cart from the Divi menu.

Divi is a popular WordPress theme that has built-in support for WooCommerce. By default, Divi displays the WooCommerce cart icon and the number of items in the cart in the header menu. However, in some cases, you may want to remove the WooCommerce cart from the Divi menu to simplify the design or layout of your site.

To remove the WooCommerce cart from the menu in Divi, you can use the et_divi_add_to_cart_link filter hook and the __return_empty_string function. Here’s an example code snippet:

function wpsnippets_remove_woocommerce_cart_from_menu( $add_to_cart ) {
    return '';
}
add_filter( 'et_divi_add_to_cart_link', 'wpsnippets_remove_woocommerce_cart_from_menu' );

In this code snippet, we define a function wpsnippets_remove_woocommerce_cart_from_menu that uses the __return_empty_string function to return an empty string, effectively removing the add-to-cart link from the menu. We hook this function to the et_divi_add_to_cart_link filter hook, which is responsible for rendering the add-to-cart link in Divi’s header menu.

You can modify the code snippet to remove or modify other elements of the header menu in Divi. Additionally, you can modify the HTML and CSS of your site to adjust the layout of the header menu without the cart.

Last updated on September 13, 2023. Originally posted on May 9, 2023.

Leave a Reply