Skip to content

Instantly share code, notes, and snippets.

@thetwopct
Last active March 15, 2023 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thetwopct/faf8b5d639d07fa13d4bf6f54dab5b36 to your computer and use it in GitHub Desktop.
Save thetwopct/faf8b5d639d07fa13d4bf6f54dab5b36 to your computer and use it in GitHub Desktop.
Tax Toggle change text of button on click
/**
* Custom code for Tax Toggle for WooCommerce - Changes text of button on click
*
* Based on Tax Toggle for WooCommerce 1.3.6
*
* Plugin: https://1.envato.market/taxtoggle
*
**/
/**
* Control the Tax Toggle button text
*
* Compatible with Version 1.3.6 of Tax Toggle.
*
**/
function tax_toggle_control_button_text() {
?>
<script>
jQuery(document).ready(function($) {
// Set your button text here.
const exc = "Exclusief BTW";
const inc = "Inclusief BTW";
// Set the button text based on the 'woocommerce_show_tax' cookie value
function setButtonTextBasedOnCookie() {
if (Cookies.get('woocommerce_show_tax') === undefined || Cookies.get('woocommerce_show_tax') === null || Cookies.get('woocommerce_show_tax') === 'false') {
$("#wcvat-toggle.wcvat-toggle-product").find("span").text( exc );
} else {
$("#wcvat-toggle.wcvat-toggle-product").find("span").text( inc );
}
}
// Set the correct text when the page loads
setButtonTextBasedOnCookie();
// Toggle the text and "on" class when the button is clicked
$("#wcvat-toggle.wcvat-toggle-product").on('click', function() {
if ($(this).hasClass("on")) {
$(this).find("span").text( exc );
} else {
$(this).find("span").text( inc );
}
});
});
</script>
<?php
}
add_action('wp_head', 'tax_toggle_control_button_text');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment