• Resolved freddyeee

    (@freddyeee)


    Hi

    I’m trying to change some text depending of the country, certain part of the the text must remain inalterable, and the whole text should be able to translate with the language switcher, but I have a doubt introduce some text-domain in the code, how to know it ?

    function personalizar_mensaje_envio_gratis() { 
    if (!function_exists('wc_get_customer_default_location')) {
    return;
    }

    // Obtener la ubicación del cliente
    $location = wc_get_customer_default_location();
    $country = $location['country'];

    // Variables para el símbolo de la moneda y el monto según el país
    $moneda = 'S/';
    $monto = '150';

    if (in_array($country, ['US', 'CA'])) {
    $moneda = '$';
    $monto = '200';
    } elseif (in_array($country, ['ES', 'FR', 'DE', 'IT'])) {
    $moneda = '€';
    $monto = '200';
    } elseif ($country === 'GB') {
    $moneda = '£';
    $monto = '200';
    }

    // Generar el mensaje en el top bar
    echo '<div class="top-bar-item">';
    echo '<img src="https://www.runayaq.com/wp-content/uploads/2023/03/xxxxxxxxx.png" alt="Envío gratis" />';
    echo __('Envío gratis por compras mayores a ', 'text-domain'); // Texto traducible con TranslatePress
    echo $moneda . $monto; // Símbolo de moneda y monto dinámico según país
    echo '</div>';
    }
    add_action('wp_footer', 'personalizar_mensaje_envio_gratis');

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support madalinaruzsa

    (@madalinaruzsa)

    Hi @freddyeee,

    To achieve this, you need to use the data-no-translation attribute on the elements you wish to exclude from translation. For more information, please refer to this documentation page.

    Thread Starter freddyeee

    (@freddyeee)

    I didn’t explain myself correctly.
    I have a top bar on my website, inside I have a short sentence (Free shipping on orders over $200) the currency and number remain inalterable, but the text should translate. With some code I change that currency and numbers depending of the user location. If I use the code this sentence can no longer translate with the language switcher, but I do want it to change.

    Plugin Support madalinaruzsa

    (@madalinaruzsa)

    Hi @freddyeee,

    Wrap the number with a <span> tag. It will generate a different string.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.