Created
December 10, 2024 04:02
-
-
Save contemplate/89a02aec83f434953be9ac6808bc4992 to your computer and use it in GitHub Desktop.
WC Smart Coupons Accept AM / PM time to schedule gifts
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
jQuery('form.woocommerce-checkout').on('change', 'input.gift_sending_date_time', function(e){ | |
let date_time_wrapper = jQuery(this).closest('.email_sending_date_time_wrapper'); | |
let gift_sending_date_time = jQuery(date_time_wrapper).find('.gift_sending_date_time').val(); | |
if ('' === gift_sending_date_time) { | |
return; | |
} | |
// Split the date and time correctly | |
let gift_sending_date_time_parts = gift_sending_date_time.split(' '); | |
let gift_sending_date = gift_sending_date_time_parts[0]; // Date part (e.g., '23-12-2024') | |
let gift_sending_time = gift_sending_date_time_parts[1]; // Time part (e.g., '06:38') | |
// If the time part has an AM/PM, we need to preserve it | |
if (gift_sending_date_time_parts[2]) { | |
gift_sending_time += ' ' + gift_sending_date_time_parts[2]; // Add AM/PM to time part (e.g., '06:38 PM') | |
} | |
// Convert date from dd-mm-yy format to yy-mm-dd format | |
gift_sending_date = gift_sending_date.split('-'); | |
gift_sending_date = gift_sending_date[2] + '-' + gift_sending_date[1] + '-' + gift_sending_date[0]; | |
// Combine the date and time parts into a full string | |
let gift_sending_date_time_time = gift_sending_date + ' ' + gift_sending_time; | |
// Pass the full date-time string to the Date function | |
let gift_sending_utc_date_time = new Date(gift_sending_date_time_time).toUTCString(); | |
let utc_date_time = new Date(gift_sending_utc_date_time); | |
let gift_sending_timestamp = Math.floor(utc_date_time.getTime() / 1000); // Remove milliseconds from timestamp. | |
// Set the timestamp value | |
jQuery(date_time_wrapper).find('.gift_sending_timestamp').val(gift_sending_timestamp); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Text Change:
text: HH:mm
domain: woocommerce-smart-coupons
context: Timepicker on the frontend side
new: hh:mm tt
File change:
/home/thebalanced/public_html/wp-content/plugins/woocommerce-smart-coupons/includes/class-wc-sc-purchase-credit.php
around line 695