Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • add_action('wp_footer', function() {
    if (!is_checkout()) return;
    ?>
    <script>
    function forcePacklinkTranslations() {
    if (typeof Packlink === 'undefined' || !Packlink.checkout) return;

    const translations = {
    "pickDropOff": "Sélectionner un point de retrait",
    "changeDropOff": "Changer de point de retrait",
    "dropOffTitle": "Le colis sera livré à :",
    "noDropOffLocationsMessage": "Aucun point de retrait n'est disponible pour l'adresse saisie",
    "pleaseChooseDropoff": "Veuillez sélectionner un point de retrait"
    };

    // Dictionnaire des traductions pour les textes bruts
    const textMappings = {
    "Package will be delivered to:": translations.dropOffTitle,
    "No drop-off locations available for the provided address.": translations.noDropOffLocationsMessage,
    "Please choose a drop-off location.": translations.pleaseChooseDropoff
    };

    // Fonction pour mettre à jour tous les éléments
    function updateAllTexts() {
    // Traitement des boutons
    document.querySelectorAll('button, .button, [role="button"]').forEach(button => {
    const btnText = button.textContent.trim();
    if (btnText === "Change Drop-Off Location") {
    button.textContent = translations.changeDropOff;
    }
    if (btnText === "Select Drop-Off Location") {
    button.textContent = translations.pickDropOff;
    }
    });

    // Traitement des textes bruts avec TreeWalker pour meilleures performances
    const walker = document.createTreeWalker(
    document.body,
    NodeFilter.SHOW_TEXT,
    { acceptNode: function(node) {
    return node.nodeValue.trim() ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
    }},
    false
    );

    let node;
    while ((node = walker.nextNode())) {
    const originalText = node.nodeValue.trim();
    if (textMappings[originalText]) {
    node.nodeValue = node.nodeValue.replace(originalText, textMappings[originalText]);
    }
    }
    }

    // Observateur pour les modifications globales
    const globalObserver = new MutationObserver(() => updateAllTexts());

    // Configuration de l'observateur
    globalObserver.observe(document.body, {
    childList: true,
    subtree: true,
    characterData: true
    });

    // Surcharge des traductions Packlink
    Object.defineProperty(Packlink.checkout, '_translations', {
    value: translations,
    writable: false,
    configurable: false
    });

    // Initialisation
    updateAllTexts();
    }

    // Démarrage du système
    const init = () => {
    forcePacklinkTranslations();
    const interval = setInterval(forcePacklinkTranslations, 100);
    setTimeout(() => clearInterval(interval), 10000);
    };

    if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
    } else {
    init();
    }
    </script>
    <?php
    }, 0);

    J’ai pu compléter ta solution !

    Salut @siteweb ,

    Excellent ce que tu as fait, merci beaucoup !

    J’aimerai completer ta solution pour changer également le message d’erreur “Please choose a drop-off location”, une idée ? Je vais chercher de mon coté et je reviendrai ici si je trouve la solution !

Viewing 2 replies - 1 through 2 (of 2 total)