News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Stay on Product Page After Add to Cart (No Redirect, No Popup)

Started by andrai2, May 06, 2025, 00:49:49 AM

Previous topic - Next topic

andrai2

Hi,

I'm using VirtueMart 4.0.12 on Joomla 4.4.12 with PHP 8.2.

I'm trying to achieve the following behavior:

When a user clicks "Add to cart", I want the page to stay on the same product — no popup, and no redirect to the cart, just the cart icon update on the right corner

Here's what I've already configured:
In VirtueMart → Configuration → Checkout, I have set
"Display modal popup upon 'Add to cart'" to "No"

Despite this setting, the user is still redirected to the shopping cart after clicking Add to cart.

Why this is necessary:
We sell low-cost products (e.g., €0.60 per item) and have a minimum order value of €7. Redirecting to the cart every time interrupts the user flow and creates unnecessary clicks. Ideally, customers should stay on the product page and continue shopping without disruption.

My understanding so far:
As I understand it, VirtueMart configuration does not offer a built-in option to fully disable the redirect and stay on the product page without a popup or cart page load.
Therefore, I think I need to create a template override by modifying the addtocart behavior

What I'm looking for:
Prevent redirection to the cart

No popup

Remain on the product or category page

Any help or advice on how to make this work would be very helpful.


Thank you!

Jumbo!

VirtueMart will always redirect you to the cart page if you turn off the "Display modal popup upon 'Add to cart'" option. If you do not want to show the modal, you must override and customise the following script in your template.

components/com_virtuemart/assets/js/vmprices.js

You can override it by copying the file to:

templates/YOUR-TEMPLATE/js/vmprices.js

Keep the "Display modal popup upon 'Add to cart'" option as yes, and then customise the "Virtuemart.cartEffect" function as per your need.

If you need professional help, you can contact me.

andrai2

Thank you Jumbo for answer! I will go now and try to make override work as you sugested!

So yeah! It worked  - but have to test it more

1. Made template override vmprices.js
2.  Finde the Virtuemart.cartEffect line 90 in vmprices.js
3. Aske chatgtp to modify add it worked
ad he said: What this change does:
Prevents Fancybox from opening.
Skips visual modal feedback entirely.
Still adds the product to the cart and updates cart module.

Virtuemart.cartEffect = function(form) {

   var dat = form.serialize();

   // Comment or remove Fancybox activity
   // if (usefancy) {
   //    jQuery.fancybox.showActivity();
   // }

   jQuery.ajax({
      type: "POST",
      cache: false,
      dataType: "json",
      timeout: "20000",
      url: Virtuemart.vmSiteurl + "index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS&format=json" + Virtuemart.vmLang + window.Itemid,
      data: dat
   }).done(function(datas, textStatus) {
      
      // Optional: Log or silently handle errors without popup
      if (datas.stat == 1 || datas.stat == 2) {
         console.log("Product added to cart:", datas.msg);
      } else {
         console.warn("Error adding to cart:", datas.msg);
      }

      // Don't show any popup, just trigger cart update
      jQuery('body').trigger('updateVirtueMartCartModule');
   });
};