Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. jQuery(document).ready(function($) {
  2.  
  3. if($('.shipping_method:checked').length > 0) { showShippingFields($('.shipping_method:checked').attr('id')); }
  4. var quantity = jQuery('input[name=quantity]').val();
  5.  
  6. $('[value=chicken]').prop("checked", true);
  7. updatePrice();
  8.  
  9. $('.container').on('change', 'input',function(e) {
  10. updatePrice();
  11. });
  12.  
  13. $('.container').on('blur', '.quantity input.input-text.qty.text', function(){
  14. var min = 10, max = 500;
  15.  
  16. if(this.value > max) {
  17. this.value = max;
  18. } if(isNaN(this.value) || !this.value){
  19. this.value = 10;
  20. } if(this.value % 5 != 0 && this.value >= min) {
  21. this.value = roundUp(this.value);
  22. }
  23.  
  24. var new_quantity = this.value;
  25. if(quantity != new_quantity || quantity >= 10 && new_quantity < 10) {
  26. quantity = new_quantity;
  27.  
  28. updatePage(quantity);
  29. }
  30. });
  31.  
  32.  
  33. function updatePrice(){
  34. num_of_people = $('.quantity input.input-text.qty.text').val();
  35. var cost = getPrice();
  36.  
  37. var total = cost * num_of_people;
  38. $('button[name=add-to-cart] span').text('$'+total.toFixed(2));
  39. }
  40.  
  41. function getPrice(){
  42. var base_price = parseFloat($('#current-price').text());
  43. var meat_cost = ($('[name*="select-meat"]:checked').attr('data-price')) ? parseFloat($('[name*="select-meat"]:checked').attr('data-price')) : 0;
  44. var total_cost = base_price + meat_cost;
  45.  
  46. // extra checkbox costs
  47. $('input[type=checkbox]').each(function(){
  48. if(this.checked) {
  49. var addon = ($(this).attr("data-raw-price")) ? parseFloat($(this).attr("data-raw-price")) : 0;
  50. total_cost += addon;
  51. }
  52. });
  53. return total_cost;
  54. }
  55.  
  56. function roundUp(x)
  57. {
  58. return Math.ceil(x/5)*5;
  59. }
  60.  
  61. function updatePage(quantity){
  62. var url = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?quantity='+quantity;
  63. $('#spinner').addClass('spinner');
  64. $('#product-content').load(url+' #product-content>div', function(responseTxt, statusTxt, xhr){
  65. if(statusTxt == "error") {
  66. alert("Error: Something Broke. Please Refresh");
  67. location.reload();
  68. }
  69.  
  70. $('[value=chicken]').prop("checked", true);
  71. updatePrice();
  72. $('#spinner').removeClass('spinner');
  73. });
  74. }
  75.  
  76. $(document).keypress(function(event){
  77. if (event.which == '13') {
  78. event.preventDefault();
  79. }
  80. });
  81.  
  82. $('body').on('click', '.shipping_method', function(){
  83. showShippingFields(this.id);
  84. });
  85.  
  86. function showShippingFields(id){
  87. // validate-required
  88. $('.delivery-info p, .pickup-info p').removeClass('validate-required woocommerce-validated');
  89. $('.shipping-option').removeClass('shipping-selected');
  90. $('')
  91.  
  92. if(id.indexOf('flat_rate') > -1){
  93.  
  94. } else if(id.indexOf('distance_rate') > -1){
  95.  
  96. }
  97. }
  98.  
  99. jQuery(function() {
  100. jQuery( "#ship_date" ).datepicker({
  101. changeYear: true,
  102. changeMonth: true,
  103. minDate: 0,
  104. dateFormat: "yy-m-dd",
  105. yearRange: "-100:+20",
  106. });
  107. $('#ship_time').timepicker();
  108. });
  109.  
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement