To run the above code in WordPress you will probably need to change the '$' symbol in the JavaScript code to the string 'jQuery', to avoid clashes with the use of the dollar symbol for other purposes in WordPress.
i.e. $( '.variation-input' ) would become jQuery( '.variation-input' ), and $.ajax would become jQuery.ajax
and so on.
Do keep the dollar symbol in the PHP code though.