We are using Google Translate to automatically translate our website but we want to exclude products in a certain category. We already accomplished that for some products by placing the <span class="notranslate">Span</span>
tag manually in the product descriptions and in the respective template files but now we want to do that for a larger quantity of products so we think using a hook would be a better way.
I want to achieve something like follows but I don't know how to correctly insert the NoTranslate span only for the product description:
add_action( 'wp', 'disable_translation' );
function disable_translation() {
// If a product in the 'Cookware' category is being viewed...
if ( is_product() && has_term( 'Cookware', 'product_cat' ) ) {
//... Wrap the product description into notranslate span to disable the translation
<span class="notranslate">???????????????????</span>
}
}
Another way to do this probably is by editing the description.php in wp-content/plugins/woocommerce/templates/single-product/tabs as follows:
<?php if ( has_term( 'Cookware', 'product_cat' ) ) {
echo "<span class='notranslate'>";
}
else {
echo "<span>";
} ?>
<?php the_content(); ?>
echo "</span>";
<?php endif; ?>
But unfortunately this resulted in the following error:
Parse error: syntax error, unexpected ‘endif’ (T_ENDIF), expecting end of file in /wp-content/plugins/woocommerce/templates/single-product/tabs/description.php on line 41
Have I misspelled something?
Could anybody kindly tell me how to do this? Thanks a lot!