<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jesper Lund &#8211; Jesper Lund&#039;s blog</title>
	<atom:link href="https://blog.jln.dk/author/jesperlndk/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.jln.dk</link>
	<description></description>
	<lastBuildDate>Wed, 21 Oct 2020 13:28:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>How To Make WooCommerce &#038; Polylang Work Together</title>
		<link>https://blog.jln.dk/how-to-make-woocommerce-work-with-polylang-wordpress/</link>
					<comments>https://blog.jln.dk/how-to-make-woocommerce-work-with-polylang-wordpress/#comments</comments>
		
		<dc:creator><![CDATA[Jesper Lund]]></dc:creator>
		<pubDate>Fri, 26 Jun 2015 12:07:06 +0000</pubDate>
				<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">http://app-ryan.mqs10q4qaj-ewx3l9zvl3zq.p.runcloud.link/?p=149</guid>

					<description><![CDATA[Note: This blog post was written in 2015, so there is no guarantee that the solution still works. However new comments keep coming in confirming that it still works (see comments section below) 🙂 If you are building a multilingual ecommerce WordPress website using the plugins WooCommerce and Polylang, you might run into a bug. Thus you &#8230; <a href="https://blog.jln.dk/how-to-make-woocommerce-work-with-polylang-wordpress/" class="more-link">Continue reading <span class="screen-reader-text">How To Make WooCommerce &#038; Polylang Work Together</span></a>]]></description>
										<content:encoded><![CDATA[<p><a href="https://blog.jln.dk/wp-content/uploads/2015/06/wordpress-woocommerce-polylang.png"><img fetchpriority="high" decoding="async" class="alignnone wp-image-160 size-full" src="https://blog.jln.dk/wp-content/uploads/2015/06/wordpress-woocommerce-polylang.png" alt="" width="600" height="106" srcset="https://blog.jln.dk/wp-content/uploads/2015/06/wordpress-woocommerce-polylang.png 600w, https://blog.jln.dk/wp-content/uploads/2015/06/wordpress-woocommerce-polylang-300x53.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<p><span style="color: #ff0000;"><strong>Note: This blog post was written in 2015, so there is no guarantee that the solution still works. However new comments keep coming in confirming that it still works (see comments section below) 🙂</strong></span></p>
<p>If you are building a <strong>multilingual ecommerce WordPress website using the plugins <a href="https://wordpress.org/plugins/woocommerce/" target="_blank" rel="noopener noreferrer">WooCommerce</a> and <a href="https://wordpress.org/plugins/polylang/" target="_blank" rel="noopener noreferrer">Polylang</a></strong>, you might run into a bug. Thus you can translate your products and product categories in your wp-admin, WooCommerce can not figure out to shift properly between your translations on the frontend. This happens because WooCommerce does not natively support Polylang&#8217;s translations. Learn here how to fix this bug.</p>
<p><span id="more-149"></span></p>
<p>While developing a multilingual ecommerce website with WordPress using WooCommerce and Polylang, I ran into this strange bug on the frontend. I had all my products, taxonomies and pages in WooCommerce translated with Polylang, and still it didn&#8217;t work.</p>
<p>The issues occurred were:</p>
<ul>
<li>shifting language on a product resulted in 404 error page</li>
<li>&#8220;Proceed to checkout&#8221; button on Cart page did not work</li>
<li>various broken links in WooCommerce</li>
</ul>
<p>I deep-dived into the codebase of WooCommerce and found that WooCommerce does not natively support or understand how Polylang&#8217;s translations work.<br />
In my debugging research, I did find a way to fix it. Here goes:</p>
<h2>How to fix WooCommerce to work with Polylang translations:</h2>
<h3>Step 1: Open the file wc-page-functions.php</h3>
<p>Navigate to this file &#8220;wp-content/plugins/woocommerce/includes/wc-page-functions.php&#8221; and open it in a text editor.</p>
<h3>Step 2: Search and replace code</h3>
<p>Find the function called &#8220;wc_get_page_id( $page )&#8221; and then this line:</p>
<p><code>$page = apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id' ) );</code></p>
<p>and replace it with:</p>
<p><code>$page = function_exists('pll_get_post') ? apply_filters( 'woocommerce_get_' . $page . '_page_id', pll_get_post ( get_option('woocommerce_' . $page . '_page_id' ) ) ) : apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id' ) );</code></p>
<h3>Step 3: Done!</h3>
<p>Fixed! Now WooCommerce understands your Polylang-translated pages 🙂</p>
<p>Curious about what the code fix does? In short it does:</p>
<ul>
<li>Checking that Polylang is installed and the function &#8220;pll_get_post&#8221; exists.</li>
<li>If above line is true, WooCommerce must look for the translated page of whatever page WooCommerce is looking for</li>
<li>&#8230; else just use the standard page.</li>
</ul>
<h2>Code fix doesn&#8217;t work? Correct your settings in WooCommerce and Polylang</h2>
<p>If applying the code fix does not solve your issue, please go through this guide and make sure your settings are exactly the same as described here.<br />
These settings are proven to make WooCommerce and WordPress understand the translation-links between WooCommerce pages, cart, checkout etc.</p>
<p>In this example I have two languages enabled: English as default/base language and Danish as second language.</p>
<ol>
<li><strong>Translate the WooCommerce required pages<br />
</strong>Login to your WordPress admin and go to &#8220;Pages&#8221;. Make sure you have created the three minimum required pages: Cart, Checkout and Terms &#8211; and you have them &#8220;translated&#8221; to the other language(s) as well.<br />
<a href="/wp-content/uploads/2015/06/settings1.png" target="_blank" rel="noopener noreferrer"><img decoding="async" class="alignnone wp-image-176" src="http://app-ryan.mqs10q4qaj-ewx3l9zvl3zq.p.runcloud.link/wp-content/uploads/2015/06/settings1.png" alt="settings1" width="600" height="306" srcset="https://blog.jln.dk/wp-content/uploads/2015/06/settings1.png 932w, https://blog.jln.dk/wp-content/uploads/2015/06/settings1-300x153.png 300w, https://blog.jln.dk/wp-content/uploads/2015/06/settings1-768x392.png 768w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li><strong>Correct your Checkout settings in WooCommerce<br />
</strong>Go to WooCommerce &gt; Settings &gt; Checkout.<br />
Make sure your pages are selected in the dropdowns in &#8220;Checkout Pages&#8221;.<br />
<a href="/wp-content/uploads/2015/06/settings2.png" target="_blank" rel="noopener noreferrer"><img decoding="async" class="alignnone wp-image-177" src="http://app-ryan.mqs10q4qaj-ewx3l9zvl3zq.p.runcloud.link/wp-content/uploads/2015/06/settings2.png" alt="settings2" width="600" height="541" srcset="https://blog.jln.dk/wp-content/uploads/2015/06/settings2.png 853w, https://blog.jln.dk/wp-content/uploads/2015/06/settings2-300x270.png 300w, https://blog.jln.dk/wp-content/uploads/2015/06/settings2-768x692.png 768w" sizes="(max-width: 600px) 100vw, 600px" /></a></li>
<li><strong>Correct your Languages settings in Polylang<br />
</strong>Go to Settings &gt; Languages (Polylang) &gt; Settings.<br />
Make sure your settings match the settings on this screenshot:<br />
<a href="/wp-content/uploads/2015/06/settings3.png" target="_blank" rel="noopener noreferrer"><img loading="lazy" decoding="async" class="alignnone wp-image-178" src="http://app-ryan.mqs10q4qaj-ewx3l9zvl3zq.p.runcloud.link/wp-content/uploads/2015/06/settings3.png" alt="settings3" width="600" height="505" srcset="https://blog.jln.dk/wp-content/uploads/2015/06/settings3.png 1014w, https://blog.jln.dk/wp-content/uploads/2015/06/settings3-300x252.png 300w, https://blog.jln.dk/wp-content/uploads/2015/06/settings3-768x646.png 768w" sizes="auto, (max-width: 600px) 100vw, 600px" /></a></li>
<li><strong>Done! You&#8217;re good to go!</strong></li>
</ol>
<h2>Disclaimer</h2>
<p>The code fix in this blog post is not the best way to solve the issue. However it is currently the only way, as WooCommerce does not natively support Polylang&#8217;s translations on the frontend.<br />
Replacing code in the plugin is a bad solution because our change can get removed/overridden when a new update of WooCommerce is installed.<br />
<span style="text-decoration: underline;">Therefore: if you do use this fix, please be careful when updating WooCommerce in the future.</span></p>
<h2>Which versions does it work with?</h2>
<p><del>2015-06-26: Tested working with WooCommerce version 2.3.11 and Polylang version 1.7.6</del><br />
<del>2015-08-12: Tested working with WooCommerce version 2.4.3 and Polylang version 1.7.8</del><br />
<del>2015-09-01: Tested working with WooCommerce version 2.4.6 and Polylang version 1.7.9</del><br />
<del>2015-10-12: Tested working with WooCommerce version 2.4.7 and Polylang version 1.7.10</del><br />
2015-12-01: Tested working with WooCommerce version 2.4.10 and Polylang version 1.7.12</p>
<h2>I love your feedback!</h2>
<p>I love to hear from you guys on how it works out for you. So please feel free to comment and share. I am happy to help as well 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.jln.dk/how-to-make-woocommerce-work-with-polylang-wordpress/feed/</wfw:commentRss>
			<slash:comments>210</slash:comments>
		
		
			</item>
	</channel>
</rss>
