0

I'm using the product variations to display numerous dropdowns. I need to hook into the dropdowns to extract the selected values from each dropdown when they change so I can then feed them to a calculator function that will return the price. Does anyone know how to accomplish this task?

Here is a screen shot:

Print on Demand product

I've added a screen shot to show a sample product. Please note there are approximately 40 widths, 120 lengths, 50 substrates and multiple margins, uv coatings and canvas stretchings. This is way too many combinations for WC to handle, not to mention the price updates required. All these values need to update 4 different quantity group prices when changed. I found some simple price update code but now I need to feed the 6 parameters to my own pricing calculator to create the 4 prices.

runamuk0
  • 784
  • 1
  • 7
  • 20

1 Answers1

2

When a variation is found it triggers the custom JS event "found_variation". You can run scripts on that event like so:

$( '.variations_form' ).on( 'found_variation', function( event, variation ) {
    console.log( variation );
});
helgatheviking
  • 25,596
  • 11
  • 95
  • 152
  • I am new to WP and WC. Where would I place your code to intercept the updates and call my own calculator? – runamuk0 Feb 26 '15 at 16:06
  • This is javascript. So you will need to load a script. See [wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script). This is only a suggestion/hopeful point in the right direction because your question is pretty broad. – helgatheviking Feb 26 '15 at 16:09
  • Code has been changed. See this answer for updated code: [http://stackoverflow.com/a/27849208](http://stackoverflow.com/a/27849208) – Eljas Jan 12 '17 at 10:58