You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

A collection of useful scripts for use on PFE/PFM/PFSR sites.

Change a text string on a page

This example is intended for the FooterExtra-mobile PagePart and shows the "Service charge" text in the Order Summary panel being changed to "$5 Minimum Order". 

<script type="text/javascript">
	var swapTextCount = 0;
	
	function swapPageText(htmlSelector, originalText, newText)
	{
		var foundIt = false;
		swapTextCount++;
		if ( htmlSelector.length > 0 && originalText.length > 0 ) {
			$(htmlSelector).each(function() {
				try {
					var htmlString = $( this ).html();
					if ( htmlString.includes( originalText ) ) {
						foundIt = true;
						var newHtmlString = htmlString.replace( originalText, newText );
						$( this ).html( newHtmlString );
					}
				}
				finally { }
			});
			
			if ((!foundIt) && (swapTextCount < 20)) {
				setTimeout( swapPageText, 150, htmlSelector, originalText, newText );
			}
		}
	}

	$(document).on("$pf-url-visited", function (event, url)
	{
		if ((url == "/cart") || (url == "/checkout/promotions") || (url == "/checkout/submit"))
		{
			swapTextCount = 0;
			setTimeout( swapPageText, 100, "span", "Service charge", "$5 Minimum Order" );
		}
	});
</script>
  • No labels