Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
5
Indexable
Never
add_action('wp_head', function(){
	?>
	<script>
		jQuery(document).ready(function(){

			function getCookie(name) {
			  const value = `; ${document.cookie}`;
			  const parts = value.split(`; ${name}=`);
			  if (parts.length === 2) return parts.pop().split(';').shift();
			}

			function setCookie(c_name,value,exdays)
			{
			    var exdate=new Date();
			    exdate.setDate(exdate.getDate() + exdays);
			    var c_value=escape(value) + ((exdays==null)
			                                 ? "" : "; expires="+exdate.toUTCString())
			                                + "; path=/";
			    document.cookie=c_name + "=" + c_value;
			}

			var button = '<button type="button" id="b2bking_show_hide">Show / Hide Prices</button><div id="styles_container"></div>';
			jQuery('body').on('click', '#b2bking_show_hide', function(){
			   show_hide();
			});
			jQuery('.site-footer').append(button);

			if (getCookie('hideprices') === 'true'){
				// click once
				show_hide();
			}

			function show_hide(){
				var style_hide = '<style type="text/css">.price, .woocommerce-Price-amount{display:none !important;}</style>';

				if (jQuery('#styles_container').html() === ''){
					jQuery('#styles_container').html(style_hide);
					setCookie('hideprices', 'true', 100);
				} else {
					jQuery('#styles_container').html('');
					setCookie('hideprices', 'false', 100);
				}
			}
		});
	</script>	
	<?php
});