Skip to content
Advertisement

WordPress Woo Minicart plugin with Polylang problem for cart strings and cart page link for different languages

I am trying to change the values of the strings in the Woo Minicart plugin 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 I just want the strings and the links to be changed according the two different languages, please help. Here is the code that I put in wmc-default-fragment.php and 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>

Please help me

Advertisement

Answer

after taking a brief look at the Polylang documentation, I found out about ‘pll_language_defined’, which executes after all the other functions. Look at it here: 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.

I used pll_language_defined, I added an action inside it.

   <?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');
                ?>

Then it was all working, they were changing correctly. After that, I had some problems though, products were being added randomly in the cart and etc. It was problem with the plugin WP Fastest Cache. If you run into this problem, make sure you have no cache enabled for the cart page, I disabled the plugin and it was all good, everything is being translated the right way and it works now.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement