Conditional text appearing on Checkout
-
Hello,
I am trying to run a script to conditionally show a message when certain states are selected. Currently, I am able to make the message trigger, but only for one state at a time. I am looking for a solution to include about 10 states that will trigger the text to pop up. How should I go about adding this to the code I already have? This is the code I’m using currently://Sales Tax Warning Script
add_action( ‘woocommerce_checkout_before_order_review’, ‘show_prop_message’ );function show_prop_message() {
echo ‘<div class=”prop65-warning woocommerce-warning” style=”display:none;”><p style=”font-size:9pt; padding:10px 10px; border:1px solid #d1d18e; background-color:#ffffb8;”>
We are now required to collect sales tax in your state. To learn more and see if you are eligible for exemption, click here. Details</p></div>’;
}// Second Step
// Show or hide warning message based on billing and shipping state
// First trigger is fired on billing state selection in case the “Ship to a different address” checkbox is unselected
// Second trigger is fired if the “Ship to a different address” checkbox is ticked
// Initally the “display:none” hides the warning message by defaultadd_action( ‘woocommerce_after_checkout_form’, ‘show_warning_message’ );
function show_warning_message(){
?><script>
jQuery(document).ready(function($){// Set the shipping state 2 char code (This selection will fire the warning message display)
// Fires secondary if shipping state is set to California
var stateCode = ‘WI’;$(‘select#billing_state’).change(function(){
selectedState = $(‘select#billing_state’).val();
if( selectedState == stateCode ){
$(‘.prop65-warning’).show();
}
else {
$(‘.prop65-warning’).hide();
}
});});
</script>
<script>jQuery(document).ready(function($){
// Set the billing state 2 char code (This selection will fire the warning message display)
// Fires initially if billing state is California
var stateCode = ‘WI’;$(‘select#billing_state’).change(function(){
selectedState = $(‘select#billing_state’).val();
if( selectedState == stateCode ){
$(‘.prop65-warning’).show();
}
else {
$(‘.prop65-warning’).hide()<?php } ?>
The topic ‘Conditional text appearing on Checkout’ is closed to new replies.