0

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
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Can you review your posted code? It is not clear which code is php and what not. There are some markers missing. – Reporter Aug 02 '21 at 11:49
  • Ref: [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming). So in short: you can't. You need a completely different mindset and techniques. – Yoshi Aug 02 '21 at 12:13
  • I think there are 2 ways. One is using Ajax & 2nd is reload the page with query string. Can anyone give me example on ajax call? – Akash Talele Aug 02 '21 at 21:32

0 Answers0