Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($) {
- if($('.shipping_method:checked').length > 0) { showShippingFields($('.shipping_method:checked').attr('id')); }
- var quantity = jQuery('input[name=quantity]').val();
- $('[value=chicken]').prop("checked", true);
- updatePrice();
- $('.container').on('change', 'input',function(e) {
- updatePrice();
- });
- $('.container').on('blur', '.quantity input.input-text.qty.text', function(){
- var min = 10, max = 500;
- if(this.value > max) {
- this.value = max;
- } if(isNaN(this.value) || !this.value){
- this.value = 10;
- } if(this.value % 5 != 0 && this.value >= min) {
- this.value = roundUp(this.value);
- }
- var new_quantity = this.value;
- if(quantity != new_quantity || quantity >= 10 && new_quantity < 10) {
- quantity = new_quantity;
- updatePage(quantity);
- }
- });
- function updatePrice(){
- num_of_people = $('.quantity input.input-text.qty.text').val();
- var cost = getPrice();
- var total = cost * num_of_people;
- $('button[name=add-to-cart] span').text('$'+total.toFixed(2));
- }
- function getPrice(){
- var base_price = parseFloat($('#current-price').text());
- var meat_cost = ($('[name*="select-meat"]:checked').attr('data-price')) ? parseFloat($('[name*="select-meat"]:checked').attr('data-price')) : 0;
- var total_cost = base_price + meat_cost;
- // extra checkbox costs
- $('input[type=checkbox]').each(function(){
- if(this.checked) {
- var addon = ($(this).attr("data-raw-price")) ? parseFloat($(this).attr("data-raw-price")) : 0;
- total_cost += addon;
- }
- });
- return total_cost;
- }
- function roundUp(x)
- {
- return Math.ceil(x/5)*5;
- }
- function updatePage(quantity){
- var url = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?quantity='+quantity;
- $('#spinner').addClass('spinner');
- $('#product-content').load(url+' #product-content>div', function(responseTxt, statusTxt, xhr){
- if(statusTxt == "error") {
- alert("Error: Something Broke. Please Refresh");
- location.reload();
- }
- $('[value=chicken]').prop("checked", true);
- updatePrice();
- $('#spinner').removeClass('spinner');
- });
- }
- $(document).keypress(function(event){
- if (event.which == '13') {
- event.preventDefault();
- }
- });
- $('body').on('click', '.shipping_method', function(){
- showShippingFields(this.id);
- });
- function showShippingFields(id){
- // validate-required
- $('.delivery-info p, .pickup-info p').removeClass('validate-required woocommerce-validated');
- $('.shipping-option').removeClass('shipping-selected');
- $('')
- if(id.indexOf('flat_rate') > -1){
- } else if(id.indexOf('distance_rate') > -1){
- }
- }
- jQuery(function() {
- jQuery( "#ship_date" ).datepicker({
- changeYear: true,
- changeMonth: true,
- minDate: 0,
- dateFormat: "yy-m-dd",
- yearRange: "-100:+20",
- });
- $('#ship_time').timepicker();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement