• Resolved adamauskas

    (@adamauskas)


    Hello, Sark!
    I am trying to fix strange issue with variation group field.
    All the group fields loading well on the page if the user picking some value from variation options. But if I set some variation as default value – group field doesn’t load on first page load. And user needs to choose another variation option and then switch back to first one if he want to configure first variation.
    You can check it on my page in attachment.

    So the question is – is there any option how to enable loading variation field group at the same time as page loads?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Sark

    (@sarkware)

    I will look into it, meanwhite put the following snippet on your active theme’s functions.php

    add_action('woocommerce_after_variations_table', 'trigger_change_event_snippet');
    function trigger_change_event_snippet() { ?>
    
    	<script type="text/javascript">
    		jQuery(document).ready(function() {			
    			$("table.variations select:first-child").trigger("change");
    		});
    	</script>
    
    	<?php
    }
    Thread Starter adamauskas

    (@adamauskas)

    @sarkware thanks for your quick reaction!
    I have added this snippet, but there is no changes on the product page yet:
    https://shop.e-locks.eu/product/product-1/

    Plugin Contributor Sark

    (@sarkware)

    Sorry, I made a mistake in the snippet, here is the updated one.

    add_action('woocommerce_after_variations_table', 'trigger_change_event_snippet');
    function trigger_change_event_snippet() { ?>
    
    	<script type="text/javascript">
    		jQuery(document).ready(function() {			
    			jQuery("table.variations select:first-child").trigger("change");
    		});
    	</script>
    
    	<?php
    }
    Thread Starter adamauskas

    (@adamauskas)

    @sarkware thank you, Sark! I reuploaded the snippet, but nothing changed. If I open that page with pre-selected variations – field group still isn’t loading.

    Plugin Contributor Sark

    (@sarkware)

    I think it triggering the change event way too early. we can add a time out like the below. It may solve the issue.

    add_action('woocommerce_after_variations_table', 'trigger_change_event_snippet');
    function trigger_change_event_snippet() { ?>
    
    	<script type="text/javascript">
    		jQuery(document).ready(function() {			
    			setTimeout(function() {
    				jQuery("table.variations select:first-child").trigger("change");
    			}, 800);			
    		});
    	</script>
    
    	<?php
    }
    Thread Starter adamauskas

    (@adamauskas)

    This one worked well! Even 400ms is OK!
    Thank you a lot!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Load field group for default variation values’ is closed to new replies.