Skip to content

Instantly share code, notes, and snippets.

@onnayokheng
Last active July 13, 2018 15:28
Show Gist options
  • Save onnayokheng/c1e990f0e2ec784b53bddacd2c3c1cd9 to your computer and use it in GitHub Desktop.
Save onnayokheng/c1e990f0e2ec784b53bddacd2c3c1cd9 to your computer and use it in GitHub Desktop.
Add countdown on thankyou page
<?php
/**
* Add countdown into view order and thankyou page
* @author: Onnay Okheng (@onnayokheng)
*/
add_action( 'woocommerce_thankyou', 'matamerah_add_countdown_checkout' );
add_action( 'woocommerce_view_order', 'matamerah_add_countdown_checkout' );
function matamerah_add_countdown_checkout($order_id = 0)
{
if ($order_id == 0) {
return false;
}
// Get object order
$order = wc_get_order( $order_id );
// Check if order is null
if ( is_null($order) ) {
return false;
}
// Check if order status is not on-hold or pending
if ( !in_array($order->get_status(), array('on-hold', 'pending') ) ) {
return false;
}
$order_date = wc_format_datetime($order->get_date_created(), 'Y-m-d H:i');
$date_time = strtotime($order_date . " + 1 day");
$new_order_date = mysql2date( get_option( 'date_format' ), date('Y-m-d H:i', $date_time) );
$new_order_time = date( 'H:i', $date_time ); ?>
<style>
.container-countdown { position: fixed; z-index: 100; bottom: 0; left: 0; width: 100%; height: auto; background: red; color: white; text-align: center; -webkit-box-shadow: 0px -3px 8px -1px rgba(0,0,0,0.2);-moz-box-shadow: 0px -3px 8px -1px rgba(0,0,0,0.2);box-shadow: 0px -3px 8px -1px rgba(0,0,0,0.2); }
.container-countdown span { font-size: 1.6rem; padding: 20px 0; display: block; }
</style>
<div class="container-countdown">
<span>Berakhir pada: <?php echo $new_order_date; ?>, pukul <?php echo $new_order_time; ?>.</span>
</div><?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment