Wordpress Woo Minicart 插件,针对不同语言的购物车字符串和购物车页面 link 存在 Polylang 问题
Wordpress Woo Minicart plugin with Polylang problem for cart strings and cart page link for different languages
我正在尝试更改 Woo Minicart 插件中的字符串值 https://wordpress.org/support/plugin/woo-minicart/ for different languages using pll_current_language() of Polylang, but I have some trouble with Polylang and the Woo Minicart plugin. I will attach a video, because the strings change for a second, then get back to the other language. Also, the different links for the different cart pages of the languages, also do not change. Here is how it looks on the frontend: https://www.youtube.com/watch?v=tYFX34ARhF0&feature=youtu.be
我只想根据两种不同的语言更改字符串和链接,请帮忙。
这是我放入 wmc-default-fragment.php 和 wmc-default-template.php:
的代码
<div class="wmc-bottom-buttons">
<?php if(pll_current_language() == 'en'){
echo '<a href="https://testb.com/en/cart/">'; }?>
<?php if(pll_current_language() == 'bg'){
echo '<a href="https://testb.com/количка/">'; }?>
<?php if(pll_current_language() == 'bg'){ _e( 'Количка', 'woo-minicart' );} else if(pll_current_language() == 'en'){_e( 'Cart', 'woo-minicart' ); }?></a>
<a href="<?php echo wc_get_checkout_url(); ?>"><?php _e( 'Поръчка', 'woo-minicart' ) ?></a>
</div>
请帮帮我
在简要浏览了 Polylang 文档后,我发现了 'pll_language_defined',它在所有其他函数之后执行。看这里:https://polylang.pro/doc/developpers-how-to/
When Polylang does load the language?
There are two cases: The language is set from the content: Polylang needs to defer the language loading and does it in a function hooked to the action 'wp' action with priority 5.
The language code is added to all urls (default): there is no need to defer the language loading and it is done as if Polylang were not active.
Due to the first case, plugin authors should not attempt to translate strings before the 'wp' action has been fired. Polylang provides a new action 'pll_language_defined' which is fired as soon as the language is defined. It works whatever the option chosen by the user to set the language.
我用的是pll_language_defined,我在里面加了一个动作
<?php
function action_pll_language_defined() {
if(pll_current_language() == 'bg'){ _e( 'Поръчка', 'woo-minicart' );} else
if(pll_current_language() == 'en') { _e( 'Checkout', 'woo-minicart' ); }
}
add_action('pll_language_defined', 'action_pll_language_defined', 10, 2);
do_action('pll_language_defined');
?>
然后一切正常,它们正在正确更改。在那之后,我遇到了一些问题,产品被随机添加到购物车等等。这是插件 WP Fastest Cache 的问题。如果您 运行 遇到这个问题,请确保您没有为购物车页面启用缓存,我禁用了该插件并且一切正常,所有内容都以正确的方式翻译并且现在可以正常工作。
我正在尝试更改 Woo Minicart 插件中的字符串值 https://wordpress.org/support/plugin/woo-minicart/ for different languages using pll_current_language() of Polylang, but I have some trouble with Polylang and the Woo Minicart plugin. I will attach a video, because the strings change for a second, then get back to the other language. Also, the different links for the different cart pages of the languages, also do not change. Here is how it looks on the frontend: https://www.youtube.com/watch?v=tYFX34ARhF0&feature=youtu.be 我只想根据两种不同的语言更改字符串和链接,请帮忙。 这是我放入 wmc-default-fragment.php 和 wmc-default-template.php:
的代码 <div class="wmc-bottom-buttons">
<?php if(pll_current_language() == 'en'){
echo '<a href="https://testb.com/en/cart/">'; }?>
<?php if(pll_current_language() == 'bg'){
echo '<a href="https://testb.com/количка/">'; }?>
<?php if(pll_current_language() == 'bg'){ _e( 'Количка', 'woo-minicart' );} else if(pll_current_language() == 'en'){_e( 'Cart', 'woo-minicart' ); }?></a>
<a href="<?php echo wc_get_checkout_url(); ?>"><?php _e( 'Поръчка', 'woo-minicart' ) ?></a>
</div>
请帮帮我
在简要浏览了 Polylang 文档后,我发现了 'pll_language_defined',它在所有其他函数之后执行。看这里:https://polylang.pro/doc/developpers-how-to/
When Polylang does load the language? There are two cases: The language is set from the content: Polylang needs to defer the language loading and does it in a function hooked to the action 'wp' action with priority 5. The language code is added to all urls (default): there is no need to defer the language loading and it is done as if Polylang were not active. Due to the first case, plugin authors should not attempt to translate strings before the 'wp' action has been fired. Polylang provides a new action 'pll_language_defined' which is fired as soon as the language is defined. It works whatever the option chosen by the user to set the language.
我用的是pll_language_defined,我在里面加了一个动作
<?php
function action_pll_language_defined() {
if(pll_current_language() == 'bg'){ _e( 'Поръчка', 'woo-minicart' );} else
if(pll_current_language() == 'en') { _e( 'Checkout', 'woo-minicart' ); }
}
add_action('pll_language_defined', 'action_pll_language_defined', 10, 2);
do_action('pll_language_defined');
?>
然后一切正常,它们正在正确更改。在那之后,我遇到了一些问题,产品被随机添加到购物车等等。这是插件 WP Fastest Cache 的问题。如果您 运行 遇到这个问题,请确保您没有为购物车页面启用缓存,我禁用了该插件并且一切正常,所有内容都以正确的方式翻译并且现在可以正常工作。