Elementor: Disable the Menu Cart Widget Default Function and Link to the Cart Page

Smart Web Creative - Elementor: Disable the Menu Cart Widget Default Function and Link to the Cart Page

If you have ever used the Elementor widget, “Menu Cart”, you are probably familiar with its features of showing the cart subtotal and item count. What if you wanted to take users to the cart page instead? Normally you would have to create a button with just an icon that links them there. But, by doing this, you lose out on having the dynamic features of the menu cart widget like the subtotal and item count.

What if there was a way to disable the menu cart widget default function and link to the cart page? This can be accomplished with some custom code.

Adding the Code

Go to your theme’s functions.php file and add the following code:

/**
* Redirect Menu Cart Widget to Cart Page
*/
function redirect_menu_cart_to_cart_page() {
// Check if the current page is the cart page
if (is_cart()) {
return;
}

// Get the URL of the cart page
$cart_page_url = wc_get_cart_url(); // WooCommerce cart URL

// Modify the URL if you're using a custom cart page URL
// $cart_page_url = site_url('/your-custom-cart-page'); // Example for custom cart page URL

?>
<script>
document.addEventListener('DOMContentLoaded', function() {
var menuCartLink = document.querySelector('#elementor-menu-cart__toggle_button');
if (menuCartLink) {
menuCartLink.addEventListener('click', function(event) {
event.preventDefault();
window.location.href = '<?php echo esc_url($cart_page_url); ?>';
event.stopPropagation(); // Prevent event propagation
});
}
});
</script>
<?php
}
add_action('wp_footer', 'redirect_menu_cart_to_cart_page');

Now when a user clicks on the menu cart widget, it will take them to your cart page. By adding this function, it enables the user to see their cart subtotal and item count, plus it takes them to the cart page.

Other Helpful Articles

Transferring Large Files

Sometimes when you have a designer or developer work on a project, you may have to send over large files to them. It is difficult for some people to send large files, especially if they aren’t tech savvy. Some of these large files might be for some graphic design project,

Read More »

Use Gmail for Webmail Accounts

If you use Gmail and you have a Webmail account, you can actually use Gmail for your Webmail accounts. There are some benefits, but also drawbacks to using this setup. It is important though that before you take the following steps, you ensure that your DNS records have the correct

Read More »

How To Create an Email Signature in Gmail/G Suite

You may have noticed many businesses and individuals will have email signatures that look professional. If you have Gmail or G Suite, there’s actually a pretty easy way to set one up. To start creating your email signature, sign in to your Gmail account. Over in the top right you’ll

Read More »

What Do You Need Done?:

(Please check all that apply)

Tell Us About You

Almost Done!

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info

Let's Get Some Info