Created
October 14, 2022 21:08
-
-
Save damadorPL/b11c725f8fa6e454ec5f4633db7995e4 to your computer and use it in GitHub Desktop.
wooocmerce time from product addition
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
add_filter( 'manage_edit-product_columns', 'add_custom_products_column',15 ); | |
function add_custom_products_column($columns){ | |
$columns['time_from_creation'] = __( 'Time from Creation'); | |
return $columns; | |
} | |
add_action( 'manage_product_posts_custom_column', 'output_time_from_creation', 10, 2 ); | |
function output_time_from_creation( $column, $post_id ) { | |
if ( $column == 'time_from_creation' ) { | |
$product = get_product($post_id); | |
$datetime_created = $product->get_date_created(); | |
$timestamp_created = $datetime_created->getTimestamp(); | |
$datetime_now = new WC_DateTime(); | |
$timestamp_now = $datetime_now->getTimestamp(); | |
$time_delta = $timestamp_now - $timestamp_created; | |
echo floor($time_delta / 60 / 60 / 24) . 'h' ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment