I have a Woocommerce website with a plugin so the costumer can add a product to his/her wishlist by pressing a button. This button has an image with a white heart. After clicking the button the white heart has to be changed in a red heart. This works, but only after the page is reloaded. So I want to let change the image real-time. I know something like AJAX is needed. The name of the image is used by the variable $cls . This one is used in the src of the image.
I have the following code:
<?php
if(is_user_logged_in()) {
$hlink=get_permalink()."?add_to_wishlist=".$post_ID;
$a=1;
} else { $hlink='/login';$a=0; }
$is_in_wishlist = YITH_WCWL()->is_product_in_wishlist( $post_ID );
if($is_in_wishlist==1) {
$cls='red';
} else {
$cls='white';
}
?>
<a href="<?php echo $hlink;?>" <?php if($a==1){ ?> rel='nofollow' <?php } ?> data-product-id="<?php echo $post_ID ?>" data-product-type="simple" class='add_to_wishlist'><img class="botButton" id="changeheartcolor" src="//voice-overs.online/wp-content/themes/Impreza-child/images/voice-overs_online_heart-<?php echo $cls; ?>.svg">
How can I make it work so the heart (image) will change directly change without refreshing the page?