• I have a product.
• In the product card there are 2 attributes (with different id’s), with two different prices.
• In wp_postmeta the product has 2(!!!) meta_key == _price.
Accordingly, the search works on the 1st price.
How to make the search work on the 2nd price?
Attribute id of the 2nd price is ‘rentfortheevent’ (‘pa_rentfortheevent’ in the attributes table in database).
Right now the search by price is done like this:
function set_price($q)
{
$min_price = $_GET["min_price"];
$max_price = $_GET["max_price"];
$meta_query = $q -> get("meta_query");
if ($min_price)
{
$meta_query[] =
[
"key" => "_price",
"value" => $min_price,
"type" => "NUMERIC",
"compare" => ">=",
];
}
if ($max_price)
{
$meta_query[] =
[
"key" => "_price",
"value" => $max_price,
"type" => "NUMERIC",
"compare" => "<=",
];
}
$q -> set("meta_query", $meta_query);
}
add_action("woocommerce_product_query", "set_price");
}