I am editing one plugin file. I want to get the selected variation id & use it in the following PHP code of the plugin. I added this code to the file but was unable to get the Variation id out of the function.
add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_display_dropdown_variation_add_cart' );
 
function bbloomer_display_dropdown_variation_add_cart() {
    
   global $product;
    
   if ( $product->is_type('variable') ) {
       
      ?>
      <script>
      jQuery(document).ready(function($) {
          
         $('input.variation_id').change( function(){
            if( '' != $('input.variation_id').val() ) {
                
               var var_id = $('input.variation_id').val();
               alert('You just selected variation #' + var_id);
                
            }
         });
          
      });
      </script>
      <?php
    
   }
    
}
Like
if ($var_id == 123) {
Custom work here
}
 
    