How can I pass URL parameters from a page in WordPress so I can use them later with woocommerce actions?
Any help is appreciated.
How can I pass URL parameters from a page in WordPress so I can use them later with woocommerce actions?
Any help is appreciated.
Here is an example of function that will grab your URL parameter in php sessions (you will have to replace in the code custom_key by your desired query var:
add_action( 'template_redirect', 'store_url_params' );
function store_url_params() {
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (isset($_GET['custom_key'])) {
// Store the value in a cookie
$_SESSION['custom_key'] = esc_attr($_GET['custom_key']);
}
}
Code goes in function.php file of your active child theme (active theme).
Then you will call the value later using:
$value = $_SESSION['custom_key'];