0

I am trying to display a value based on woocommerce quantity input and i'm using the following jQuery script.

<script>
jQuery(function($){
    var form = 'form.variations_form',       selected = 'input[name="variation_id"]',
    attrVal = 'input#attr-hidden';

    var price = <?php echo $product->get_price(); ?>;
    $(form).on( 'blur', 'select', function() {
        if($(selected).val() != ''){
            if(($(attrVal).val() == 'Black') && ($('[name=quantity]').val() >= 1 && $('[name=quantity]').val() <= 50)){ 
                print_price = '15'
            }
            if(($(attrVal).val() == 'Black') && ($('[name=quantity]').val() >= 51 && $('[name=quantity]').val() <= 100)){  
                print_price = '10'
            }
        } 
    });

    var currency = '<?php echo get_woocommerce_currency_symbol(); ?>';

    $('[name=quantity]').change(function(){
        if (!(this.value < 0)) {
            var print_product_total = parseFloat(print_price * this.value);

            $('#print_total_price .print_price').html( currency + print_product_total.toFixed(2));
        }
        $('#print_total_price').toggle(!(this.value <= 0));
    });
});

What this script does is that if selected attribute of a product is "Black" and quantity input is greater that 1 and less that 50 is displays a field with value "15" and if it is greter that 51 and less than 100 it displays "10".

The problem is that if i enter quantity 1 and then changed it to 51 it still displays "15" unless i select again the attribute "Black".

  • This is pretty JavaScript/jQuery-specific. You might have more luck over on StackOverflow with this type of question. – WebElaine Oct 16 at 21:14

Your Answer

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

Browse other questions tagged or ask your own question.