Created
February 11, 2026 05:33
-
-
Save rajeshsingh520/6975f9166de0f2cc8367f4ef7badc021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TwentyTwenty_Custom_Scripts { | |
| private static $instance = null; | |
| public $hide_field_name = 'delivery-address'; | |
| public static function get_instance() { | |
| if ( is_null( self::$instance ) ) { | |
| self::$instance = new self(); | |
| } | |
| return self::$instance; | |
| } | |
| private function __construct() { | |
| add_action( 'wp_enqueue_scripts', [ $this, 'restrict_date_pickers' ] ); | |
| add_action( 'wp_enqueue_scripts', [ $this, 'pickup_delivery_logic' ] ); | |
| add_filter('pisol_eqw_form_validation', [$this, 'validate_pickup_delivery'], 10, 2); | |
| } | |
| public function validate_pickup_delivery($errors, $items){ | |
| foreach($items as $item){ | |
| if($item['type'] == 'datetime' && isset($_POST[$item['name']])){ | |
| $selected_date_time = $_POST[$item['name']]; | |
| $selected_date = wp_date('Y-m-d', strtotime($selected_date_time)); | |
| $current_date = current_time('Y-m-d'); | |
| if(strtotime($selected_date) < strtotime($current_date)){ | |
| $errors[] = ['error'=>'Dont select past date']; | |
| } | |
| } | |
| } | |
| return $errors; | |
| } | |
| public function restrict_date_pickers() { | |
| $wp_today = current_time( 'Y-m-d' ); | |
| $wp_now = current_time( 'Y-m-d\TH:i' ); | |
| $inline_js = " | |
| (function() { | |
| function restrictDates() { | |
| var today = '{$wp_today}'; | |
| var localISOTime = '{$wp_now}'; | |
| var dateInputs = document.querySelectorAll('input[type=\"date\"]'); | |
| for (var i = 0; i < dateInputs.length; i++) { | |
| dateInputs[i].setAttribute('min', today); | |
| } | |
| var dateTimeInputs = document.querySelectorAll('input[type=\"datetime-local\"]'); | |
| for (var j = 0; j < dateTimeInputs.length; j++) { | |
| dateTimeInputs[j].setAttribute('min', localISOTime); | |
| } | |
| } | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', restrictDates); | |
| } else { | |
| restrictDates(); | |
| } | |
| })(); | |
| "; | |
| wp_add_inline_script( 'twentytwenty-js', $inline_js ); | |
| } | |
| public function pickup_delivery_logic() { | |
| $inline_js = " | |
| (function($) { | |
| $(document).ready(function() { | |
| function togglePickupDelivery() { | |
| var checked = $('input[name=\"pickup-or-delivery\"]:checked').val(); | |
| if (checked === 'Delivery') { | |
| $('input[name=\"".$this->hide_field_name . "\"]').show() | |
| } else { | |
| $('input[name=\"".$this->hide_field_name . "\"]').hide() | |
| } | |
| } | |
| $('input[name=\"pickup-or-delivery\"]').on('change', togglePickupDelivery); | |
| togglePickupDelivery(); | |
| }); | |
| })(window.jQuery); | |
| "; | |
| wp_add_inline_script( 'twentytwenty-js', $inline_js ); | |
| } | |
| } | |
| // Initialize | |
| TwentyTwenty_Custom_Scripts::get_instance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment