natestylez
Forum Replies Created
-
You can see my working example here:
https://www.nextlevelperf.com/products/I ended up using my own solution loosely based off the developers last reply and my previous attempts. I am not an expert programmer by any means though, so I don’t know if this would be considered a proper or efficient way, but it is working for my site.
Here was my solution, this was added to my child theme’s functions.php file:
// Set Vehicle Filter for Session// function vehicle_filter_setcookie() { //Detect WOOF get variables in URL and save to session data if they exist// if (!is_admin() && isset($_GET['vehicle']) && isset($_GET['product_make'])) { $_SESSION['ses_product_make'] = $_GET['product_make']; } //This IF statement prevents WOOF results from overriding homepage content// if (!is_admin() && $_SERVER["REQUEST_URI"] != '/' && isset($_SESSION['ses_product_make'])) { $_GET['product_make'] = $_SESSION['ses_product_make']; } //Unset WOOF selections if 'reset_vehicle' variable is posted// if (isset($_POST['reset_vehicle'])) { unset($_GET['product_make']); unset($_SESSION['ses_product_make']); } } add_action( 'init', 'vehicle_filter_setcookie' );
Then I created a form to clear the session data, therefor clearing WOOF settings. This is what I used for that:
<form action="" method="post"> <input type="hidden" name="reset_vehicle" value="true" /> <button>CHANGE VEHICLE</button> </form>
I tried this with no luck…
In functions.php
// Set Vehicle Filter for Session// function vehicle_filter_setcookie() { if (!is_admin() && isset($_GET['vehicle']) && isset($_GET['product_make'])) { $_SESSION['product_make'] = $_GET['product_make']; } //Reset post/session data if reset_vehicle is posted if (isset($_POST['reset_vehicle'])) { unset($_GET['product_make']); unset($_SESSION['product_make']); } } add_action( 'init', 'vehicle_filter_setcookie' ); function vehicle_filter_restore() { return apply_filters('woof_get_request_data', $_SESSION); }
In my header.php file:
<?php if (is_woocommerce()){ vehicle_filter_restore(); } ?>
Am I doing it wrong?
Thank you for your reply RealMag777,
Can you please give me an example of how I would use the get_request_data() function in my script I posted above?
The knowledge-base you linked doesn’t show any examples of usage or any description of what the function does…
Thank you!!