I am using JavaScrip to show/hide a certain element if a certain checkbox is checked. In my case, if the "Freight forwarding" checkbox is not checked, I would like to hide deposit payment options.
I have added deposit.js in my child theme and enqueued it by adding the following code in functions.php
function load_hide_deposit_script() {
if( is_page(98) ) {
//script location - child theme//
wp_enqueue_script( 'js-file', get_stylesheet_directory_uri() . '/deposit.js');
}
}
add_action('wp_enqueue_scripts', 'load_hide_deposit_script');
I checked developer tools and the script is loaded successfully.
Based on How to show/hide an element on checkbox checked/unchecked states using jQuery?
I have used two approaches:
function valueChanged()
{
if($('.input-checkbox.thwcfe-input-field').is(":checked"))
$(".cart-wcdpp-fields.order-total").show();
else
$(".cart-wcdpp-fields.order-total").hide();
}
and
$(".cart-wcdpp-fields.order-total").hide();
$(".input-checkbox.thwcfe-input-field").click(function() {
if($(this).is(":checked")) {
$(".cart-wcdpp-fields.order-total").show(300);
} else {
$(".cart-wcdpp-fields.order-total").hide(200);
}
});
So far I haven't achieved desired result with these codes.
What could be the problem?
Link to the shop page (testing site) - https://siakurjers.wpengine.com/shop/
To check the functionality please add a product to the cart and visit the checkout page.