Including the + symbol in the query string
-
Hi guys, quick question. I use Elementor Pro and WooCommerce. I noticed a strange behaviour for this plugin:
I have this product: BMW 3-Series 2019+ (G20-G21) and the URL is:
https://carsoundsecurity.co.uk/?s=&ymm_search=1&post_type=product&_make=BMW&_model=3-Series&_year=2019%2B%20(G20-G21)
When I click on a filter, the + is ignored and the products associated with this model are not returned:
https://carsoundsecurity.co.uk/p-rear-screens/?s&ymm_search=1&post_type=product&_make=BMW&_model=3-Series&_year=2019+%20(G20-G21)
Filtering products without + in their titles works great. The problem is when the %2B is present.
I started with this snippet, but then the %20 is ignored. Can you guys give me an idea about how can I handle special characters with your plugin? Many thanks!
add_action('woocommerce_product_query', 'custom_year_filter');
function custom_year_filter($query) {
if (isset($_GET['_year'])) {
$year = sanitize_text_field($_GET['_year']);
if (strpos($year, '+') === false) {
$year = str_replace(' ', '+', $year);
$_GET['_year'] = $year;
}
}
}
- You must be logged in to reply to this topic.