Hello,
Also it is possible to filter the woocommerce API response by YMM make, model and year.
Add the code:
add_filter("woocommerce_rest_product_object_query", 'pofw_filter_woocommerce_rest_response', 10, 2);
function pofw_filter_woocommerce_rest_response($args, $request)
{
$values = array();
if (isset($_GET['_make'])){
$values[] = sanitize_text_field(stripslashes($_GET['_make']));
if (isset($_GET['_model'])){
$values[] = sanitize_text_field(stripslashes($_GET['_model']));
if (isset($_GET['_year'])){
$values[] = (int) $_GET['_year'];
}
}
}
if (!empty($values)){
include_once( Pektsekye_YMM()->getPluginPath() . 'Model/Db.php');
$db = new Pektsekye_Ymm_Model_Db();
$pIds = $db->getProductIds($values);
$args['post__in'] = $pIds;
}
return $args;
}
To the end of the file:
wp-content/plugins/ymm-search/ymm-search.php
Then test it with an API query like this:
https://yourwebsite.com/wp-json/wc/v3/products/?_make=BMW&_model=X5&_year=2009&consumer_key=ck_13b0584736a06d5d3fb52a153dbc170fe68de417&consumer_secret=cs_a6f6cccd47030e9fa2d45eabd0eb1936e5e124b8
To return only ids:
https://yourwebsite.com/wp-json/wc/v3/products/?_fields=id&_make=BMW&_model=X5&_year=2009&consumer_key=ck_13b0584736a06d5d3fb52a153dbc170fe68de417&consumer_secret=cs_a6f6cccd47030e9fa2d45eabd0eb1936e5e124b8
Replace API keys with the keys of your WordPress website.
Stanislav