Home › Forums › WoodMart support forum › Event on variation swatch
Event on variation swatch
- This topic has 14 replies, 2 voices, and was last updated 5 years, 5 months ago by
Artem Temos.
-
AuthorPosts
-
October 1, 2019 at 1:15 pm #147845
MikeParticipantHello.
I have created a small snippet that calls “show_variation” event from woocommerce’s add-to-cart-variation.js which provides the variation object on JS.
My problem is that my snippet works great when there is no swatch (when variation select box is visible) but when I have color swatches, the function is not triggering or dealying much to trigger.I have tried to add event on variation swatch click but the hidden variation_id on form delays as well to change, so I get false data.
I have temporary added setTimeout of 1 sec, to get it working but I really need to find an event when swatch changes (on_swatch_change or similar)Thanks
October 1, 2019 at 2:24 pm #147871
Artem TemosKeymasterHi,
Try to use the
found_variation
event instead. It should work correctly.Kind Regards
October 30, 2019 at 2:29 pm #153490
MikeParticipantHello again, we try the “found_variation” event insteed of “show_variation” as i have described before, but hte problem still occurs as you can see in the video, when a product have swatches variation the installments are aren’t update instantly only when i double click on the swatches, on the video i also showing you that this is working correct when the product not have swatches but only select box, so is there any other solution to correct this or maybe the theme needs any update or other method for such thing? thank you in advance
October 30, 2019 at 2:35 pm #153493
Artem TemosKeymasterCould you please send us the code snippet and where we can see it on your website?
October 30, 2019 at 2:41 pm #153495
MikeParticipantsure check attachment please, thank you
edit: its not allowing me to upload a php so i have upload it on my Onedrive
October 30, 2019 at 2:55 pm #153497
Artem TemosKeymasterWe don’t know what is wrong with your code. We tested the event and it works correctly with swatches. Here is a code that we tried
jQuery(document).on( 'found_variation', 'form.cart', function( event, variation ) { alert(1); });
Regards
October 30, 2019 at 3:57 pm #153519
MikeParticipanti already tried this, the alert function its doesn’t work at all, its just throw a number on the page. do you want to give you a login credentials to check it by yourself? because i have tried every know method for this and nothing its working, so maybe its need to implement a different method on theme side who knows…
October 31, 2019 at 7:22 am #153669
MikeParticipantbump.
October 31, 2019 at 7:51 am #153701
Artem TemosKeymasterI have tried to add the code to the Custom JS section in Theme Settings and the alert function is working correctly now https://gyazo.com/4270fe1a464cc0267ed99401d83ee780
October 31, 2019 at 7:57 am #153703
MikeParticipantand im telling you again i already tried this, this is not what im looking for, i bet you don’t see the video at all. please check the video on my previous comment to understood what its not working, the alert function it just throw a number on select swatches and there is no point why to do that. please give an attention on the video. thank you
October 31, 2019 at 7:59 am #153704
Artem TemosKeymasterInitially, you wrote that
event on variation swatch
is not working. And my code with alert proves that the event actually works. It works with both swatches and standard dropdowns. And that means that the problem with your custom code, not with the event and our theme. You need to review your code and check what is wrong with that, not with the theme or events system. Sorry, but reviewing 3d party customization code is out of our theme support scope.October 31, 2019 at 8:11 am #153712
MikeParticipantim not request you to check my code, im just asking for support and for specific thing, the swatches are part of the theme and im just looking and asking you if there is another method to call the event, as you can see on the video my problem is that when i try to select a differnet product variation (in this case they displayed as swatches and not the default woocommerce select box) im getting false values on the price calculator below. this is a custom snippet that just display the product price on installments example if a product cost 500 on 2 installments its display 250 for 2 installments and so on, but when the product has higher price on different swatch variation example black color the event its not instant and, i mean that the price dosen’t get the correct instantly but you need to click again the variation to display it correct, this is something like a stuck/delay or something.
October 31, 2019 at 9:13 am #153752
Artem TemosKeymasterim just asking for support and for specific thing
Yes, but this thing is not our default functionality but related to the code you added. If you will remove all your customizations, our theme will work correctly.if there is another method to call the event
This event system is a part of the WooCommerce plugin and there is only one method to call it.October 31, 2019 at 9:14 am #153753
MikeParticipantI am using WooCommerce default hooks and nothing is 3rd-party
Give it a go by yourself. Try the following hooks on a select box change and on variation change. You will see that variation wont be accurate on found_variationjQuery(document).on( ‘found_variation’, ‘form.cart’, function( event, variation ) {
console.log(variation.variation_id);
});jQuery( “.single_variation_wrap” ).on( “show_variation”, function ( event, variation ) {
console.log(variation.variation_id);
});October 31, 2019 at 9:22 am #153755
Artem TemosKeymasterWe have added the code and here is a result https://gyazo.com/24a2ff490bf5972631a7f25f4d688764
-
AuthorPosts
- You must be logged in to create new topics. Login / Register