Skip to content

Instantly share code, notes, and snippets.

@mdibrahimk48
Created June 7, 2023 13:07
Show Gist options
  • Save mdibrahimk48/e81bd9f4e88fe0ed9421414aeff5e28c to your computer and use it in GitHub Desktop.
Save mdibrahimk48/e81bd9f4e88fe0ed9421414aeff5e28c to your computer and use it in GitHub Desktop.
JavaScript customizer code for convert date timestamp to human readable format (For Plugin - Woo Product Table by CodeAstrology)
<?php
function codeastrology_wpt_date_format()
{
?>
<script>
jQuery(function($) {
'use strict';
$(document).ready(function() {
/**
* USED CSS code:
* div.wpt-wrap table.wpt_product_table tbody tr.wpt_row>td.wpt_jet-date-debut.wpt_temp_13 {
white-space: nowrap;}
.wpt-hide-dateformate{display:none !important;}
}
* It's used in customizer.
*/
function convertNumberToDate(){
$('table.wpt_product_table tr.wpt-row').each(function(){
var Row = $(this);
var prevDateNumber = Row.find('td.wpt_jet-date-debut div.item_jet-date-debut_13');
var timestamp = prevDateNumber.text();
var isNumber = $.isNumeric(timestamp);
if(isNumber){
timestamp = parseInt(timestamp);
var formattedDate = $.datepicker.formatDate('yy-mm-dd', new Date(timestamp * 1000));
prevDateNumber.addClass('wpt-hide-dateformate').hide();
Row.find('td.wpt_jet-date-debut').append('<div class="wpt-new-date-formate">' + formattedDate + '</div>');
}
});
}
convertNumberToDate();
$(document.body).on('wpt_ajax_load_data',convertNumberToDate);
});
});
</script>
<?php
}
add_action('wp_footer', 'codeastrology_wpt_date_format');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment