How to Set Categories in Two Languages in WooCommerce with Polylang (Beginner-Friendly Guide)
So, you’ve got a WooCommerce store, and you’re ready to go global! Fantastic! One of the first steps to making your products available to a wider audience is translating your product categories. Polylang is a fantastic plugin that makes multilingual WordPress sites, including WooCommerce stores, relatively simple to manage. This guide will walk you through setting up your product categories in two languages using WooCommerce and Polylang.
Why Translate Your Product Categories?
Imagine this: you’re selling handcrafted leather bags. A customer in Spain visits your website. They might not know what “Shoulder Bag” means, but they definitely understand “Bolso de hombro.” Translating your product categories provides a better user experience, improves your SEO for different language audiences, and ultimately boosts your sales. It’s about making your products easily discoverable for *everyone*.
Prerequisites
Before we dive in, make sure you have these things set up:
- WordPress Installed: You should have a working WordPress installation.
- WooCommerce Installed and Configured: You’ve already set up your WooCommerce store and have some products (even if they are just placeholders).
- Polylang Plugin Installed and Activated: This is the star of the show! You can find it in the WordPress plugin repository. Just search for “Polylang” and install/activate it.
- Two Languages Set Up in Polylang: You’ve configured Polylang with your default language (e.g., English) and the language you want to translate into (e.g., Spanish).
- Name: The translated name of the category. For “Hats,” you might enter “Sombreros.”
- Slug (Optional): The translated slug of the category. The slug is the URL-friendly version of the name. You can leave this blank, and WordPress will automatically generate it based on the translated name. If you’re manually setting the slug, use lowercase letters and hyphens (e.g., “sombreros”). If the slug is important for SEO in the translated language, then definitely translate the slug.
- Description (Optional): If you have a description for your category, translate that too! This is important for SEO and provides additional context to your customers.
- Parent Category (If Applicable): If this is a subcategory, make sure you select the translated parent category. This helps maintain the same category structure in both languages.
- Name: “Winter Zubehör”
- Slug: (Generated automatically, or we can manually set it to “winter-zubehoer”)
- Description: (Translated description of winter accessories)
- Translations Not Showing: Make sure you’ve properly assigned the translations to the correct language using the “+” icon. Also, double-check that your language switcher is working correctly and that you’ve configured your menu to display the translated categories.
- Category Hierarchies Messed Up: Carefully check that you’ve selected the correct translated parent categories for your subcategories. Incorrect parent assignments can lead to a confusing category structure.
- SEO Issues: Make sure your translated slugs are optimized for search engines in the translated language. Research the keywords people use when searching for products like yours in that language.
If you haven’t set up Polylang languages yet, here’s a quick guide:
1. Go to Languages > Languages in your WordPress dashboard.
2. Choose your desired languages from the dropdown and click “Add new language.”
3. Polylang will guide you through setting your default language and configuring how language switching will work (usually through a language switcher in your menu or URL structure).
Step-by-Step Guide: Translating Your Product Categories
Now for the main event! Let’s get those categories translated.
1. Accessing Your Product Categories:
Navigate to Products > Categories in your WordPress dashboard. This will show you a list of all your existing product categories.
2. Editing Your Default Language Category:
Click on the category you want to translate. For example, let’s say we want to translate the “Hats” category.
3. Adding the Translation:
You’ll see a section on the right-hand side of the category edit page that lists your configured languages. Next to the language you want to translate into (e.g., Spanish), you’ll likely see a “+” icon. Click this icon.
4. Entering the Translated Category Details:
You’ll be taken to a new category page specifically for the translated language. Here you’ll enter:
5. Saving Your Translation:
Once you’ve entered the translated details, click the “Add New Category” or “Update” button (depending on whether you are creating a new category or translating an existing one).
6. Repeat for Other Categories:
Repeat steps 2-5 for all the product categories you want to translate.
Example: Translating “Winter Accessories” to German
Let’s walk through a quick example:
1. We have a category called “Winter Accessories” in our default language (English).
2. We click on the “Winter Accessories” category to edit it.
3. On the right side, next to “German,” we click the “+”.
4. On the new category page, we enter:
5. We click “Add New Category.”
Now, when a user switches to the German version of our site, they’ll see “Winter Zubehör” instead of “Winter Accessories.”
Troubleshooting Common Issues
Going the Extra Mile: Code Snippets (For Advanced Users)
Sometimes, you might need to get a little more hands-on. Here are a couple of snippets (use with caution, and always back up your site first!):
1. Getting the Translated Category URL Programmatically:
If you need to display the translated category URL in your theme or a custom plugin, you can use the following code:
<?php $category_id = 123; // Replace with the ID of your category $translated_category_id = pll_get_term( $category_id, pll_current_language() );
if ( $translated_category_id ) {
$category_link = get_term_link( $translated_category_id, ‘product_cat’ );
if ( ! is_wp_error( $category_link ) ) {
echo ‘Translated Category Link‘;
}
} else {
echo ‘Translation not found’;
}
?>
Explanation:
- `pll_get_term()`: This Polylang function retrieves the translated term (in this case, a category) ID based on the original category ID and the current language.
- `get_term_link()`: This WordPress function gets the URL of the translated category.
- The code checks for errors and displays a link to the translated category or a “Translation not found” message if the translation doesn’t exist.
2. Displaying Category Name in Correct Language:
<?php $category_id = 123; // Replace with the ID of your category $translated_category_id = pll_get_term( $category_id, pll_current_language() );
if ( $translated_category_id ) {
$category = get_term( $translated_category_id, ‘product_cat’ );
if ( ! is_wp_error( $category ) ) {
echo esc_html( $category->name ); // Display translated category name
}
} else {
echo ‘Translation not found’;
}
?>
This snippet gets the translated category ID and then retrieves the category object to display its name in the current language.
Conclusion
Translating your WooCommerce product categories is a crucial step in creating a successful multilingual store. By following these steps, you can ensure that your products are easily discoverable and accessible to a wider audience, leading to increased sales and a better user experience. Remember to pay attention to detail, particularly when it comes to slugs and category hierarchies. Good luck, and happy translating!