0

I am using WooCommerce for my eCommerce website, I have added a custom checkout field "Delivery Date Picker" with the help of the official WooCommerce plugin "Checkout Field Editor" in my shipping field.

There is no option in the Checkout field editor plugin backend to disable delivery on a particular date or holiday.

Suppose due to holiday; I want to disable delivery on 25,26 December or 1 January, then how can I disable delivery date on these particular dates?

Thank you in advance!

1

As you are using plugin, you need to override plugin functionality using hooks. So, in your case, we need to override date picker functionality in your theme's functions.php file.

unavailableDates is a variable where you need to pass the dates that need to be disable and other functional code indicate that you need to destroy current date picker function and re-initiate the date picker function as per your requirement using wp_footer hook.

Below is the code snippet that i have created and it is fully logical.

add_action('wp_footer', 'wp_footer_callback');
function wp_footer_callback(){
?>
<script type="text/javascript">
    jQuery(document).on('ready', function(){
        var unavailableDates = ["17-12-2019", "19-12-2019", "15-12-2019"];
        function unavailable(date) {
            dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
            if (jQuery.inArray(dmy, unavailableDates) == -1) {
                return [true, ""];
            } else {
                return [false, "", "Unavailable"];
            }
        }
        jQuery(".checkout-date-picker").datepicker("destroy");
        jQuery(".checkout-date-picker").datepicker({
            dateFormat: 'dd MM yy',
            beforeShowDay: unavailable
        });

    });
</script>
<?php   
}

Let me know if it does not help.

| improve this answer | |
  • Thank you so much, You saved my day :) – Brajmohan Kumar Jan 31 at 11:46

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.