Untitled
unknown
plain_text
a year ago
2.5 kB
9
Indexable
add_action('wp_footer', 'toggle_price_button'); function toggle_price_button() { if (function_exists('b2bking')){ if (b2bking()->is_b2b_user()){ if (isset($_COOKIE['hide_prices']) && $_COOKIE['hide_prices'] == '1') { echo '<style> .price, .amount, .woocommerce-price-suffix, .b2bking_tiered_price_table { display: none; } </style>'; } ?> <button id="toggle-price-button">Hide/Show</button> <script type="text/javascript"> document.addEventListener('DOMContentLoaded', function() { var button = document.getElementById('toggle-price-button'); var priceElements = document.querySelectorAll('.price, .amount, .woocommerce-price-suffix, .b2bking_tiered_price_table'); var hidePrices = getCookie('hide_prices'); if (hidePrices === '1') { priceElements.forEach(function(el) { el.style.display = 'none'; }); } button.addEventListener('click', function() { if (getCookie('hide_prices') === '1') { setCookie('hide_prices', '0', 365); priceElements.forEach(function(el) { el.style.display = ''; }); } else { setCookie('hide_prices', '1', 365); priceElements.forEach(function(el) { el.style.display = 'none'; }); } location.reload(); }); function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } }); </script> <?php } } }
Editor is loading...
Leave a Comment