hyyan / woo-poly-integration

Looking for maintainers! - Wordpress WooCommerce Polylang Integration
https://wordpress.org/plugins-wp/woo-poly-integration/
MIT License
183 stars 66 forks source link

REST API support for limiting returned language versions #514

Open richard-grosjean opened 4 years ago

richard-grosjean commented 4 years ago

Using the REST API, the WooCommerce products endpoint returns all language versions.

Based on #23 and my measly testing, it seems like using a parameter like "lang" to filter the language versions that the products endpoint returns is not currently possible.

Adding support for a param like this seems trivial, but I haven't looked into where and how to best place it in this plugin or even if the maintainer feels like a feature like this is desirable in this plugin (❤️ this plugin hyyan, hope you find your maintainer).

There might be a better (less general) hook to use, but here is some example code to help illustrate the feature:

add_action('parse_query', 'add_lang_support', 1);

function add_lang_support($query) {
  $lang = $_GET['lang'];
    if ($lang) {
    $lang = sanitize_text_field($lang);
    $query->set('lang', $lang);
  }
}
Jon007 commented 3 years ago

I agree, the code suggested looks along the right lines, you are welcome to submit a pull request..! as there isn't rest customisation currently I'd suggest a new file. To follow the existing plugin scheme it would be a new class file in src/Hyyan/WPI and a line to create it in registerCore() in Plugin.php... potentially also added as a setting in Features.php which allows the various features to be turned on and off. at least that's how the other bits are implemented in this plugin.