title: WMPL get WooCommerce product category in a specific language
body: <p>I am developing a WooCommerce multi language store using Wordpress 4.6, WPML 3.5, WooCommerce Multilingual 3.8.6 and WooCommerce version 2.6.4.</p>
  
  <p>The code always return categories in the primary language but never returns the translation for the specified language.</p>
  
  <p>Here is the code:-</p>
  
  <pre><code>    private $lang;
  
      function __construct($lang = "en") {
          $this-&gt;lang = $lang;
      }
  
      private function getCategories() {
          try {
                  $api = WC()-&gt;api-&gt;WC_API_Products;
                  $categories = $api-&gt;get_product_categories();
  
                  $products_categories = $categories["product_categories"];
  
                  foreach($products_categories as $category) {
                      $id = absint($category["id"]);
                      $category["name"] = $this-&gt;get_translated_term_name($id, "product_cat", $this-&gt;lang);
                  }
  
                  return $products_categories;
  
              } catch (Exception $e) {
                  error_log("Caught $e");
              }
      }
  
      private function get_translated_term_name($term_id, $taxonomy, $language) {
  
          $translated_term_id = icl_object_id($term_id, $taxonomy, true, $language);
  
          $translated_term_object = get_term_by('id', $translated_term_id, $taxonomy);
  
          return $translated_term_object-&gt;name;
      }
  </code></pre>