Last active
March 15, 2023 16:32
-
-
Save thetwopct/faf8b5d639d07fa13d4bf6f54dab5b36 to your computer and use it in GitHub Desktop.
Tax Toggle change text of button on click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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