Chat Disclaimer Before Messaging

Description/Instructions

This is a way to add a disclaimer to the chats before starting a new message with the user.

If this snippet helped, feel free to buy me a taco :)

function add_custom_text_to_div() {
?>
<script>
function updateStartConvoDiv() {
var startConvoDiv = document.querySelector('.start-convo');
if (startConvoDiv) {
// Create a container for the new messages
var messageContainer = document.createElement('div');
messageContainer.className = 'chat-messages';
messageContainer.style.maxWidth = '500px'; // Set max-width directly via JavaScript
messageContainer.style.margin = '0 auto'; // Centers the div within .start-convo

// Text content before the link
var newText1 = document.createTextNode('We analyze messages for safety, support, product enhancement and other purposes. ');
messageContainer.appendChild(newText1);

// Create the link
var learnMoreLink = document.createElement('a');
learnMoreLink.href = 'https://calvertchamber.org/chats';
learnMoreLink.textContent = 'Learn more';
learnMoreLink.style.color = '#0073aa'; // Optional: Style the link color
messageContainer.appendChild(learnMoreLink);

// Line break after the link
var lineBreak = document.createElement('br');
messageContainer.appendChild(lineBreak);

// Text content after the link
var newText2 = document.createTextNode(' To protect your payment, always pay through the Calvert Chamber of Commerce website.');
messageContainer.appendChild(newText2);

// Append the container to the .start-convo div
startConvoDiv.appendChild(messageContainer);

startConvoDiv.style.textAlign = 'center'; // Center align everything in the div
} else {
// Try again in 100 milliseconds if the div isn't found
setTimeout(updateStartConvoDiv, 100);
}
}

document.addEventListener('DOMContentLoaded', updateStartConvoDiv);
</script>
<?php
}
add_action('wp_footer', 'add_custom_text_to_div');

  • PHP
Copy Code

Let's Chat About this Snippet