ulc_view_codes_time_format
Filters the time format used for displaying codes, allowing customization of how time is presented.
add_filter( 'ulc_view_codes_time_format', $callback, 10, 1 );
Description
Filters the time format used for displaying coupon codes in the admin view. Developers can use this hook to customize the time display globally, overriding the default WordPress time format. This hook fires when generating the HTML for individual coupon code rows.
Usage
add_filter( 'ulc_view_codes_time_format', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Modify the time format used for displaying coupon expiration dates.
*
* This function is a callback for the 'ulc_view_codes_time_format' filter.
* It allows developers to change the default time format provided by WordPress.
*
* @param string $time_format The current time format.
* @return string The modified time format.
*/
function my_custom_coupon_time_format( $time_format ) {
// Example: Append seconds to the default time format if it exists.
// This assumes the default format might not include seconds.
if ( strpos( $time_format, 's' ) === false ) {
// Get the current WordPress time format and append seconds.
// We can also use a hardcoded format like 'H:i:s' or 'g:i:s a'.
$wordpress_time_format = get_option( 'time_format' );
return $wordpress_time_format . ':s';
}
return $time_format;
}
add_filter( 'ulc_view_codes_time_format', 'my_custom_coupon_time_format', 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/admin/class-view-codes.php:112
*/
public function single_row( $coupon ) {
$codes_batch_id = absint( $coupon->code_group );
$r = '<tr>';
list( $columns ) = $this->get_column_info();
$date_format = apply_filters( 'ulc_view_codes_date_format', get_option( 'date_format' ) );
$time_format = apply_filters( 'ulc_view_codes_time_format', get_option( 'time_format' ) );
// Optimize: Call get_users_of_code once and reuse the result
$code_users = Database::get_users_of_code( $coupon->ID, false );
foreach ( $columns as $column_name => $column_display_name ) {
$r .= '<td class="column-' . $column_name . '" data-label="' . esc_attr( $column_display_name ) . '">';
switch ( $column_name ) {