Jump to content

Redirect to custom page after adding product to cart


Recommended Posts

Hello there!

Was hoping someone would be able to help me with this little problem I'm having.

Basically what I'm trying to do is have PrestaShop redirect the customer to a custom page after they click the add to cart button. At the moment it is being redirected to the shopping cart, but I would like to be able to specify a different address if possible, maybe a page created in CMS or a different product in the system.

I know it sounds odd but there is a method to my madness, and I'll be sure to show you my reasoning if someone can guide me on how to do it :)

Many thanks,
Richard

Link to comment
Share on other sites

To redirect to another page I edited the order.php file to include this code:

<?php
$ipa = addslashes($_REQUEST['ipa']);
if ($ipa == 11) {
Header( "HTTP/1.1 301 Moved Permanently" );
header("Location: www.site1.com");
exit;
} else if ($ipa == 12) {
Header( "HTTP/1.1 301 Moved Permanently" );
header("Location: www.site2.com");
exit;
}
?>

IPA is the item number to redirect and then the page is the site to redirect.
This method WILL add the item to the cart but redirects the person to an external page, 1 problem I noticed is when you remove the item from the cart you are also redirected.

WHAT I WANT TO DO IS:
I would like to have it redirect to the external site and NOT add the item to the shopping cart, any idea on how to do this?

I would also like to change the wording of the "add to cart" button also.

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Hi

Does anybody know how / where to do this, as I wish to do a similar thing of when a user adds an item to the cart from the product.php page, they get redirected back to the product-list page (or category.php), and don't stay on the product page.

I have been playing with the product.tpl file adding a href to this line:

quantity == 0} style="display:none;"{/if} id="add_to_cart" class="buttons_bottom_block"><input type="submit" name="Submit" value="{l s='Add to order'}" class="exclusive" /></p>



But doesnt seem to work.

Any advice would be appreciated.

Thanks

Link to comment
Share on other sites

  • 1 month later...

Ok so better late than never, I have the solution.. sort of. I have it working on our Custom PC Builder on our website, basically every time you click the big green "Continue" button it is adding the product to the cart but redirecting the user to a different page instead of the cart.

The way we have it set up is a bit more complicated than the solution I'm about to give, but this will allow you to redirect users to a custom page once the customer hits the "Add to cart" button, whilst still having the product added to their cart.

Known Issues:

First of all this wont work if you have the Ajax cart enabled, so disable it in the module settings first. I don't see it as a big problem as the customer probably wont get to see all of the pretty animation if the page redirects quick enough.

Second issue is that when the customer clicks the + and - button on the cart page, it will still redirect the user to the custom page you specify. Hopefully there are some clever people on here that can help you with that because I don't know how to do it.

Instructions

First open up "cart.php" in your favourite text/PHP editor.

Find the following code at line 138:

Tools::redirect('order.php?'.(isset($idProduct) ? 'ipa='.intval($idProduct) : ''));



REPLACE that line with the following:

{
if ($delete) {
Tools::redirect('order.php?'.(isset($idProduct) ? 'ipa='.intval($idProduct) : ''));
} else {
Tools::redirect('any-page-you-like.php');
}
}



Obviously, you will need to replace "any-page-you-like.php" with the URL that you want the user to be redirected to once they add the product to their cart.

Good luck!

Link to comment
Share on other sites

×
×
  • Create New...