I'm trying this code because I want to see the price of the product change dynamically when in the input field of the quantity exchange the number (this only for the products that have the tier price). For example if I write in the input of quantity 50, in the product page I want to see the first final price written, otherwise if I write 100 I want to see the updated price of the product. This is the code that I tried to use but without success:

span class="tierprice">/span> input type="text" name="qty" id="qty" value="getProductDefaultQty() * 1 ?>" title="__('Qty') ?>" class="input-text qty" />

                <script type="text/javascript">
                var $j = jQuery.noConflict();

                    // probably you want a custom method in your block for getting a better and safer tierPrices array here
                    // for example with formatted prices
                    var tierPrices = <?php echo json_encode($_product->getTierPrice()) ?>;
                    var getPrice = function(qty){
                        qty = Number(qty);
                        var i = tierPrices.length;
                            if(qty >= tierPrices[i]['price_qty']){
                                return tierPrices[i]['price'];
                        return null;
                    var updatePrice = function(price){
                    // you can use more events here if you want a live response while the user is typing
                        var price = getPrice(this.value);
                        if(price !== null){

Where is the error?

1 Answer 1


Idk if it will help you, but I managed to get it working by using $ outside and jQuery on the inside of the script.

    var qty = jQuery("#qty").val();

        url: 'your/url/path',
        method: 'POST',
        data: {
            'qty': qty,
        success: function (json) {
            var data = jQuery.parseJSON(json);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.