In stock delivery date at single product page

0.0/5
<?php
add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_display_dropdown_variation_add_cart' );
 
function bbloomer_display_dropdown_variation_add_cart() {
    
   global $product;
    
   if ( $product->is_type('variable') ) {
       
      ?>
      <script>
      jQuery(document).ready(function($) {
          
         $('input.variation_id').change( function(){
            if( '' != $('input.variation_id').val() ) {
               	var holidayArray = ['1-1','1-5','8-5','5-7','6-7','28-9','28-10','17-11','24-12','25-12','26-12']; /*Czech public holidays in the format "day-month" */
		var myDate = new Date(); /*Get today's date*/
				
		var easterMonth;
		var easterDay;
				
		/* Calculate Easter Friday as per https://en.wikipedia.org/wiki/Date_of_Easter */
		var year = myDate.getFullYear();
		var a = year % 19;
		var b = year % 4;
		var c = year % 7;
				
                var k = Math.floor(year/100);
                var p = Math.floor((13 + 8*k)/25);
                var q = Math.floor(k/4);
                
                var M = (15 - p + k - q) % 30;
                var N = (4 + k - q) % 7;
                
                var d = (19*a + M) % 30;
                var e = (2*b + 4*c + 6*d + N) % 7;
                
                easterDay = ((d + e - 9) > 0) ? (d + e - 9) : (22 + d + e);
		easterMonth = ((d + e - 9) > 0) ? 4 : 3;
				
		if (easterDay == 26 && easterMonth == 4)
		        easterDay = 19; /*Correction for historical reasons*/

		var easterSunday = new Date(easterDay + "/" + easterMonth + "/" + year); 
			    
		var easterMonday = new Date(easterSunday.getTime());
	        easterMonday.setDate(easterMonday.getDate() + 1); /*Shift by 1 day to get Easter Monday*/
		holidayArray.push(easterMonday.getDate() + '-' + (easterMonday.getMonth() + 1));

	        var easterFriday = new Date(easterSunday.getTime());
                easterFriday.setDate(easterFriday.getDate() - 2); /*Shift back by 2 days to get Easter Friday*/
		holidayArray.push(easterFriday.getDate() + '-' + (easterFriday.getMonth() + 1));
			    
			    
		do myDate.setDate(myDate.getDate() + 1);
                while (myDate.getDay() == 6 || myDate.getDay() == 0 || holidayArray.includes(myDate.getDate() + '-' + (myDate.getMonth() + 1) ))
                
				$("p.in-stock").text('Skladem. Odesíláme ' + myDate.toLocaleDateString());  
            }
         });       
      });
      </script>
      <?php
    
   }
    
}

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

Author

Tags