I think you can maybe use $_SESSIONS or a $_GET var.
Option 1: (I think this will work best for you situation)
function redirect_form() {
if (isset($_POST["var1"]) && !empty($_POST["var1"]) && isset($_POST["var2"]) && isset($_POST["var3"]) && !empty($_POST["var3"])) {
$_SESSION['var2'] = htmlentities(stripslashes(trim($_POST["var2"])), ENT_QUOTES);
if ($_POST["var1"] == 'product1'){
wp_redirect(home_url('/products/product1/')); exit;
///// And In your price adjustment call
function return_custom_price($price, $product) {
global $post, $blog_id;
$price = get_post_meta($post->ID, '_regular_price');
$post_id = $post->ID;
$price = ($price[0] + $_SESSION['var2']);
return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
Note: And at the top of your functions.php file, you’ll need to start $_SESSIONS in order to use them.
function register_my_session(){
if( !session_id()){
session_start();
}
}
add_action('init', 'register_my_session');
Option 2: (If you run into $_SESSION issues)
function redirect_form() {
if (isset($_POST["var1"]) && !empty($_POST["var1"]) && isset($_POST["var2"]) && isset($_POST["var3"]) && !empty($_POST["var3"])) {
$url_parm = htmlentities(stripslashes(trim($_POST["var2"])), ENT_QUOTES);
if ($_POST["var1"] == 'product1'){
wp_redirect(home_url('/products/product1/?var2='.$url_parm)); exit;
///// And In your price adjustment call
function return_custom_price($price, $product) {
global $post, $blog_id;
$price = get_post_meta($post->ID, '_regular_price');
$post_id = $post->ID;
$price = ($price[0] + $_GET['var2']);
return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
If you take Option 2, I would maybe think about protecting doing some checks and balances in your return_custom_price()
call to make sure you have clean data;
Hope that helps and let me know if you running into any issues!!