Viewing 5 replies - 1 through 5 (of 5 total)
  • Install the plugin and go to settings > Post Expirator

    Shortcode is [postexpirator]. And default to the settings on the settings page.

    Attributes are dateformat, timeformat.

    Eg.
    [postexpirator dateformat='l F jS, Y']

    To get this in a template I’ve just checked the database and the date is stored as a timestamp with a meta_key of _expiration-date.

    get_post_meta( get_the_ID(), "_expiration-date", TRUE );

    Elliot – i was wondering if i did this correctly. I added it to the content-product.php template :
    ‘<div class=”product-details”>
    <div class=”product-details-container”>
    <h3 class=”product-title”>“><?php the_title(); ?></h3>
    <?php echo $product->get_sku(); ?><?php echo apply_filters( ‘woocommerce_short_description’, $post->post_excerpt ) ?>
    <?php echo get_post_meta( get_the_ID(), ‘_expiration-date’, TRUE ); ?>’

    And on the page i see this displayed: 1414875720
    obviously i am trying to get the date displayed instead of numbers. do you have any ideas?
    i can’t display a link to the site as it is in mamp. thanks in advance ??
    lisa

    If you’re doing this in a template you need to know what you’re doing with PHP.

    The time is stored as a timestamp, a universal time code (the number of seconds since the epoch). All dates/times can be worked out from this. Eg. there’s 20 seconds difference between a timestamp of 300 and 320.

    https://uk3.php.net/manual/en/function.date.php

    $expiration_timestamp =  get_post_meta( get_the_ID(), '_expiration-date', TRUE );
    echo date( 'l F jS, Y', $expiration_timestamp );

    hi elliot – thanks so much for your help! i got it to work. Of course the true test will be when the site is live and fully populated but with my few products i seem to have it showing up correctly. ??

    Glad you got it working. If you check out the PHP date link there’s many ways you can format the displayed date.

    This will only fail if a timestamp doesn’t exist. You should error check for that. Obviously that will happen if you don’t set and Expiration date/time.

    $expiration_timestamp =  get_post_meta( get_the_ID(), '_expiration-date', TRUE );
    if( empty( $expiration_timestamp ) )
    {
    	echo 'No end date';
    }
    else
    {
    	echo date( 'l F jS, Y', $expiration_timestamp );
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display date of expiration?’ is closed to new replies.