Home › Forums › WoodMart support forum › Implementing login trigger for « Add to Wishlist » button
Implementing login trigger for « Add to Wishlist » button
- This topic has 7 replies, 2 voices, and was last updated 1 year ago by
Luke Nielsen.
-
AuthorPosts
-
February 14, 2024 at 12:46 am #539721
ggmaitreParticipantHello Xtemos Support Team,
I hope this message finds you well. I am currently working on a customization for my website using your theme, and I need assistance with a specific functionality.
I am trying to implement a feature where clicking the “Add to Wishlist” button triggers the login page (login-side-opener) if the user is not logged in (detected by is_user_logged_in()). However, I’m having difficulty locating the logic for the add_to_wishlist_single_btn button in the code.
Could you please guide me on where I can find the logic for the “Add to Wishlist” button? I would like to add a condition to check whether the user is logged in, and if not, trigger the login page.
February 14, 2024 at 4:14 pm #540043
Luke NielsenKeymasterHello,
All logic is situated in JS files and it would be impossible to override via child theme.
We have the “Only for logged-in” option for the wishlist, so you can try to use it: https://take.ms/Igyyn
Kind Regards
February 14, 2024 at 4:18 pm #540046
ggmaitreParticipantI found a solution using a custom function :
function catch_clic_wishlist() {
?>
<script type=”text/javascript”>
jQuery(document).ready(function($) {
// Définir la fonction pour intercepter le clic sur le bouton de la wishlist
function catchClicWishlist(e) {
if (!woodmartThemeModule.$body.hasClass(‘logged-in’)) {$(‘.login-side-opener’).trigger(‘click’);
}
}
$(‘body’).on(‘click’, ‘.wd-wishlist-btn a’, catchClicWishlist);
});
</script>
<?php
}where I handle the click on the wishlist button and check if the client is logged in. So far, so good.
However, the heart icon still increments, whereas I would like this behavior not to occur until the user is logged in, perhaps through a method like: e.preventDefault() ?
February 14, 2024 at 4:26 pm #540053
Luke NielsenKeymasterHello,
Such modification requires complicated code customization which is not covered by our support, sorry. Hope you can understand our limitations.
Kind Regards
February 14, 2024 at 4:36 pm #540062
ggmaitreParticipantGreat, thank you very much! In this case, to save me some time, could you provide me with the specific location of the JavaScript folder that contains the logic for incrementing the wishlist icon (the little heart)?
I could then add a condition to check if the user is logged in before incrementing it.
I am aware of the risks as I am a developer, but I have rarely worked on custom WP themes.February 14, 2024 at 4:46 pm #540069
Luke NielsenKeymasterHello,
Add to wishlist (https://take.ms/kBU6O): woodmart/js/scripts/wc/wishlist.js , counter is in the same file: https://take.ms/pA5WT
Kind Regards
February 14, 2024 at 5:00 pm #540081
ggmaitreParticipantOh great ! Exactly what I wanted 🙂
Have a great day
February 14, 2024 at 5:29 pm #540096
Luke NielsenKeymasterHello,
You are welcome! Always remember that you can reach out to us with any questions you may have.
Have a good day!
Kind Regards
-
AuthorPosts
The topic ‘Implementing login trigger for « Add to Wishlist » button’ is closed to new replies.
- You must be logged in to create new topics. Login / Register