Back button

Have to click the button twice - Back button

Have to click the button twice

by cerberus » Sat Oct 24, 2026 11:55 pm

Hi,

If you have the store set to Display Cart After Adding Product to "False", then on the product page after you have added a item to the cart a message appears saying "XXX has been added to your cart".

Then you need to click the back button twice, once to go back to before the "XXX has been added to your cart" message, then again to go back to the previous page.

Can anything be done about that ?

It works fine if you dont add the product to cart, then it needs just one click to go back.

Thank you,
Steve
cerberus
100+
Posts: 134
Joined: Sun Sep 06, 2026 10:54 pm
Phoenix Version: v1.1.0.7
Contact:

Re: Have to click the button twice

by Omar_one » Sun Oct 25, 2026 2:37 pm

Hi Steve,
Yes, this happens because when a user adds a product to the cart with Display Cart After Adding Product set to False, the page typically submits a form or performs a POST request and reloads itself to show the "XXX has been added to your cart" message. This action registers a new entry in the browser's history stack. Consequently, clicking a standard history.back() takes the user back to that exact same product page state before the notification message, requiring a second click to truly leave the product page.

Could you share why this setting is configured to False? Is it just a temporary setup until you go live, or is this intended for the long term?

Best regards,
Omar
Omar_one
500+
Posts: 715
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Contact:

Re: Have to click the button twice

by cerberus » Sun Oct 25, 2026 3:14 pm

Hi Omar,
Thank you for your reply.

I have just been experimenting, I have not decided what way to go as the shop is not live yet, but going by what you say I will set it to "True".

I did have it set to "True" to begin with, and I had raiwas continue shopping button in the cart, so then it created a circuit (so to speak) when a item was added to the cart, but there was a issue with raiwas continue shopping button in the cart (raiwa has now fixed it).

So now it should be fine with your Back Button as now I have set the shop display cart after adding a item back to true :)

Have a good day
Steve
cerberus
100+
Posts: 134
Joined: Sun Sep 06, 2026 10:54 pm
Phoenix Version: v1.1.0.7
Contact:

Re: Have to click the button twice

by Omar_one » Sun Oct 25, 2026 3:22 pm

If you would still prefer to keep 'Display Cart After Adding Product' set to False, I can investigate further and provide a solution.
Omar_one
500+
Posts: 715
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Contact:

Re: Have to click the button twice

by cerberus » Sun Oct 25, 2026 3:29 pm

ok thank you, maybe look into it if it is not too difficult ? (I have no idea about these things). I think it maybe better if the "display cart after adding product" was set to false, but if it is not a simple task to do it will be ok as it is.
cerberus
100+
Posts: 134
Joined: Sun Sep 06, 2026 10:54 pm
Phoenix Version: v1.1.0.7
Contact:

Re: Have to click the button twice

by Omar_one » Sun Oct 25, 2026 9:40 pm

If the shop not live yet try this module
https://phoenixcart.org/forum/app.php/a ... store_mode
Anyway you will have the fix tomorrow
Omar_one
500+
Posts: 715
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Contact:

Re: Have to click the button twice

by cerberus » Sun Oct 25, 2026 10:15 pm

Hi,
Thank you for doing that.
Have a good evening :)

Steve
cerberus
100+
Posts: 134
Joined: Sun Sep 06, 2026 10:54 pm
Phoenix Version: v1.1.0.7
Contact:

Re: Have to click the button twice

by Omar_one » Mon Oct 26, 2026 7:27 pm

It was not a simple task
Replace the contents of your tpl_pi_back_button.php file with the following:
let me know if its work for your

Code: Select all

<?php
/*
  $Id$
  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org
  Copyright (c) 2026 Phoenix Cart
  Released under the GNU General Public License
*/
?>
<div class="col-sm-<?= (int)PI_BACK_CONTENT_WIDTH; ?> pi-back-button  mt-4 mb-4">
  <?= 
    new Button(
      PI_BACK_BUTTON_TEXT,
      'fas fa-arrow-left',
      'btn btn-secondary btn-lg w-100 shadow-sm rounded-pill d-flex align-items-center justify-content-center gap-2',
      [],
      'javascript:piGoBack();'
    )
  ?>
</div>
<script>
(function () {
  var page  = location.href.split('#')[0];
  var key   = 'pi_back_steps';
  var steps = 1;

  try {
    var nav  = performance.getEntriesByType('navigation')[0];
    var type = nav ? nav.type : 'navigate';
    var ref  = (document.referrer || '').split('#')[0];
    var saved = JSON.parse(sessionStorage.getItem(key) || 'null');
    var known = (saved && saved.page === page) ? saved.steps : 1;

    if (type === 'reload' || type === 'back_forward') {
      // Same history entry shown again: keep what we had
      steps = known;
    } else if (ref === page) {
      // Reached this page from itself (add to cart + redirect)
      steps = known + 1;
    } else {
      // Arrived from any other page: normal single step back
      steps = 1;
    }

    sessionStorage.setItem(key, JSON.stringify({ page: page, steps: steps }));
  } catch (e) {}

  window.piGoBack = function () {
    history.go(-steps);
  };
})();
</script>
Omar_one
500+
Posts: 715
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Contact:

Re: Have to click the button twice

by cerberus » Mon Oct 26, 2026 8:24 pm

Hi Omar,

Just had a quick test and it all seems to work fine, thank you for doing that.

For me it all seems hard, for you to say it was not a simple task says it was REALLY hard to do, I do appreciate it, thank you again.

Have a good evening,
Steve
cerberus
100+
Posts: 134
Joined: Sun Sep 06, 2026 10:54 pm
Phoenix Version: v1.1.0.7
Contact: