Renato Pimpão
Renato Pimpão

Reputation: 135

Can't translate string in Functions.php using Polylang Wordpress Plugin

I have a custom code in functions.php (Wordpress) and I want to be able to translate the string "Teclado para hóspedes". No matter what the string it's not translated. Am I doing something wrong?

add_action( 'woocommerce_review_order_before_submit', 'bbloomer_checkout_add_on', 9999 );

    function bbloomer_checkout_add_on() {
   $product_ids = array( 3876 );
   $in_cart = false;
   foreach( WC()->cart->get_cart() as $cart_item ) {
      $product_in_cart = $cart_item['product_id'];
      if ( in_array( $product_in_cart, $product_ids ) ) {
         $in_cart = true;
         break;
      }
   }
   if ( ! $in_cart ) {
  echo '<font size="4" color="black" margin-left"5">Teclado para hóspedes</font>';
      echo '<p><a class="button" style="margin-left: 1em; margin-right: 0.3em; width: auto;background-color: #d83564;color: white;vertical-align: text-bottom;font-weight:normal;" href="?add-to-cart=3876"> Adicionar +79,99€ </a></p>';   
   }
}

add_action('init', function() {
  pll_register_string('mytheme-hello', 'Teclado para hóspedes');

});

Upvotes: 1

Views: 373

Answers (1)

Vkuter
Vkuter

Reputation: 247

Update you code

echo '<font size="4" color="black" margin-left"5">Teclado para hóspedes</font>';

with

echo '<font size="4" color="black" margin-left"5">' . pll__('Teclado para hóspedes') . '</font>';

Upvotes: 1

Related Questions