How to Display Dates or Other Attributes on the Checkout Page

Hi everyone,

I am currently using the RentalHive theme on my HivePress-based website and I need some assistance with showing specific attributes, such as dates, on the checkout page. I would be grateful if anyone could provide some guidance or suggestions on this topic. Here are my questions:

1- How can I modify the RentalHive theme to display booking dates on the checkout page? Are there any specific hooks or filters that I need to use for this purpose?

2- Is there an easy way to display custom attributes, such as rental item features, on the checkout page? Can I achieve this through theme customization or by customize any plugins?

I appreciate any help or suggestions from the community. Thanks in advance!

Hi Mustafa,

Sure, we can provide general guidance regarding customizations. Please let me know if you’re familiar with coding.

  1. The checkout page is implemented by WooCommerce so I recommend using their hooks. The booking ID is stored in the hp_booking meta of the purchased product, this way you can get the booking object and all the related attributes.

  2. Yes, if you get the booking object and you’re familiar with coding you can embed extra details in the checkout form.

Thank you fot your response! @ihor

Unfortunately, I cannot find the relevant data when I try the filter below. I need to get the booked dates. Can you tell me where I made a mistake by examining the function below for this?

function display_hp_booking_meta_on_checkout() {
    if ( ! is_checkout() ) {

    $cart_items = WC()->cart->get_cart();

    foreach ( $cart_items as $cart_item ) {
        if ( isset( $cart_item['hp_booking'] ) ) {
            $booking_id = $cart_item['hp_booking'];
            $booking = get_post( $booking_id );
                <?php var_dump($booking); ?>
            if ( $booking ) {

                echo '<div class="hp-booking-meta">';
                echo '<h3>Rezervation Info:</h3>';
                echo '<p>Rezervation ID: ' . $booking_id . '</p>';
                echo '<p>Rezervation Created Date: ' . $booking->post_date . '</p>';
                echo '</div>';
add_action( 'woocommerce_checkout_before_customer_details', 'display_hp_booking_meta_on_checkout' );

var_dump($booking) =>

object(WP_Post)#5754 (24) {
  string(1) "1"
  string(19) "2023-05-05 17:07:34"
  string(19) "2023-05-05 17:07:34"
  string(0) ""
  string(5) "#1258"
  string(0) ""
  string(5) "draft"
  string(6) "closed"
  string(6) "closed"
  string(0) ""
  string(0) ""
  string(0) ""
  string(0) ""
  string(19) "2023-05-05 17:07:34"
  string(19) "2023-05-05 17:07:34"
  string(0) ""
  string(57) ""
  string(10) "hp_booking"
  string(0) ""
  string(1) "0"
  string(3) "raw"

If you have a better suggestion that I have come up with a solution in this way, I would like to implement it.

function display_hp_booking_times_on_checkout() {
    if ( ! is_checkout() ) {

    global $wpdb;

    $cart_items = WC()->cart->get_cart();

    foreach ( $cart_items as $cart_item_key => $cart_item ) {
        $booking_id = isset( $cart_item['hp_booking'] ) ? $cart_item['hp_booking'] : false;

        if ( $booking_id ) {
            $start_time_meta_key = 'hp_start_time';
            $end_time_meta_key = 'hp_end_time';

            $times_query = $wpdb->get_row(
                    "SELECT start_times.meta_value AS start_time, end_times.meta_value AS end_time
                    FROM {$wpdb->posts} AS bookings
                    INNER JOIN {$wpdb->postmeta} AS start_times ON ( bookings.ID = start_times.post_id AND start_times.meta_key = %s )
                    INNER JOIN {$wpdb->postmeta} AS end_times ON ( bookings.ID = end_times.post_id AND end_times.meta_key = %s )
                    WHERE bookings.ID = %d",

            if ( ! empty( $times_query ) ) {
                $start_time = date( 'F j, Y', $times_query['start_time'] );
                $end_time = date( 'F j, Y', $times_query['end_time'] );

                echo '<div class="hp-booking-times">';
                echo '<h3>Booking Times:</h3>';
                echo '<p>Start Time: ' . $start_time . '</p>';
                echo '<p>End Time: ' . $end_time . '</p>';
                echo '</div>';
add_action( 'woocommerce_checkout_before_customer_details', 'display_hp_booking_times_on_checkout' );

Please try using this code to get the booking object by ID:


Then you can get any details this way:

echo $booking->display_dates();

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.