Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
7
Indexable
add_action('wp_head', function(){
	
	if (b2bking()->is_b2b_user()){
		?>
		<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('.page-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
	}
	
});
Editor is loading...