Home Forums WoodMart support forum Event on variation swatch

Event on variation swatch

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #147845

    Mike
    Participant

    Hello.
    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

    #147871

    Artem Temos
    Keymaster

    Hi,

    Try to use the found_variation event instead. It should work correctly.

    Kind Regards

    #153490

    Mike
    Participant

    Hello 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

    #153493

    Artem Temos
    Keymaster

    Could you please send us the code snippet and where we can see it on your website?

    #153495

    Mike
    Participant

    sure check attachment please, thank you

    edit: its not allowing me to upload a php so i have upload it on my Onedrive

    #153497

    Artem Temos
    Keymaster

    We 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

    #153519

    Mike
    Participant

    i 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…

    #153669

    Mike
    Participant

    bump.

    #153701

    Artem Temos
    Keymaster

    I 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

    #153703

    Mike
    Participant

    and 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

    #153704

    Artem Temos
    Keymaster

    Initially, 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.

    #153712

    Mike
    Participant

    im 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.

    #153752

    Artem Temos
    Keymaster

    im 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.

    #153753

    Mike
    Participant

    I 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_variation

    jQuery(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);
    });

    #153755

    Artem Temos
    Keymaster

    We have added the code and here is a result https://gyazo.com/24a2ff490bf5972631a7f25f4d688764

Viewing 15 posts - 1 through 15 (of 15 total)