I have some issue with WPML. I use two different product page fro the phisical product and for the video lessons. Now I added one more language to the project ussin WPML plugin. And It's okay but my chunk of code I using for changed the template does not work. I use this code for changing template:

add_filter( 'template_include', 'bsl_single_product_template_include', 50, 1 );
function bsl_single_product_template_include( $template ) {
if ( is_singular('product') && (has_term( 'cosmetics', 'product_cat')) ) {
    $template = get_stylesheet_directory() . '/woocommerce/single-product-cosmetics.php';
   return $template;

How it should work: there is a product page and there is a video tutorial page. These pages have different templates. To change the template I use the code shown above. But after installing and configuring the second language when switching to the template does not occur. For example, I am on a physical product page, I switch the language and the page changes to the default one, although the product page should remain.

  • You could ask directly in WPML support forum. Commented Feb 10, 2022 at 10:09
  • Is the term name still "cosmetics" in the other language? This seems like it may be an issue with how WPML handles multilingual terms. Commented Feb 10, 2022 at 10:41
  • @JacobPeattie It's weird but yes the term name still "cosmetics" in the other language. And I think you are really right the WPML multilingual terms handles most likely generates this problem. Commented Feb 10, 2022 at 12:27

1 Answer 1


Hi everyone I have found the solution. I think the comment of the @JacobPeattie help me to do that. Thank you @JacobPeattie! And here is the solution: in my code I use if statement for chacking what product category is:

if ( is_singular('product') && (has_term( 'cosmetics', 'product_cat')) )

But I did not take into account the fact that the WPML changes the category for the extra language. That's my fault. Now I will know that. And here is the correct code:

add_filter( 'template_include', 'alexandra_template_include', 15, 1 );
function alexandra_template_include( $template ) {
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;

if(is_product() &&  in_array( 'cosmetics', $categories) || in_array( 'cosmetics- 
en', $categories)){
    $template = get_stylesheet_directory() . '/woocommerce/single-product- 
   return $template;

I need it for specific purposes. But maybe it will be useful for someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.