I have landing page out of my website, with subdomain is, lets say:
lp.test.com
On this page I have button “buy” that works great, with the link (example):
http://destination.com/?add-to-cart=10960&mobile=yes
When I click on this button, it take us to the destination.com cart and add the product to the cart – as I said – it works great.
What I want is to get the previous page url and display it on cart page.
I tried 2 ways:
session and query string.
I see that WooCommerce is removing any query string so the url is just destination.com/cart, without the string after that.
So I tried sessions:
On the first page I have put on first line:
<?php
session_start();
$_SESSION['previous_location'] = 'mobile';
?>
On the second (destination) page, I have put:
$previous_location = $_SESSION['previous_location'];
echo 'Session: '. $previous_location;
But also it didn’t work. The echo is empty, it’s printing only 'Session: '
.
My goal is to recognize if customer came to the cart from external landing page, if he does – I want to display other get_header()
of my WordPress.
(update)
You need to use this code in your function.php file, to test if
session_start();
is not used yet by wordpress / woocommerce:So you will only need on the second (destination) page:
This time you will get for
$previous_location;
==> mobileAnother way could be to use PHP cookies.
On first page (at the beginning of your php document):
, null , false , true); ?>
on second page: