Add Offers count and best price to request block

Hello, I would like to add information on the request block about the current number of offers for the specific request and also show which one offers the best price. So customers can easily see without clicking on the request that it has some activity on there and see how many people offered for it. Need just simple information like on the attached image.
image

Is there any snippet for this? Or if not, what would be the best approach to do this? I think many people would find it useful. Any guidance will be very appreciated, thank you.

Hi,

Unfortunately there’s no simple code snippet for this, but if you’re familiar with coding or have a developer for custom work, I recommend calculating the number of offers and caching it on every offer update (adding/deleting), also calculating the minimum price and saving both details for the request, then inserting these details into the request template.

Hope this helps

P.S. We recently started offering customization service if you consider this option Customize your website | HivePress

Hello,

I found a way to display the number of offers to requests, so I am sharing it with you :

I created my own plugin, with a template file :
\my-plugin\templates\request\view\request-created-date.php

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
?>
<time class="hp-listing__created-date hp-meta" datetime="<?php echo esc_attr( $request->get_created_date() ); ?>">
	<?php printf( hivepress()->translator->get_string( 'added_on_date' ), $request->display_created_date() ); ?>
	<?php 
	//OCO : added nb of offers to the requests. 
	$totalcomments = get_comments_number(); echo '| <b>Offres reçues : '. $totalcomments.'</b>'; ?>
</time>

Result :

Hello, thank you for providing this but it doesn’t work for me. I’m not sure I understand how to do this right. I’ve created

wp-content/plugins/my-request-mods/my-request-mods.php with this so I can activate the plugin

<?php

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

and in there I’ve created

my-request-mods/templates/request/view/request-created-date.php

with your provided code.

When I activate the plugin, nothing happens. What am I doing wrong? Could you please provide more guidance? Thank you

My bad !

I have the file where I said it should be, but that’s a mistake (an attempt I forgot to delete).

Copy the file under your child theme instead, and it should work smoothly (at least it does for me).

\themes\your-child-theme\hivepress\request\view\request-created-date.php

1 Like

Alright I got it finally working as I like. Now it shows the number of posted comments/offers and also from them the cheapest one. Here is the updated full code. Someone might find it helpful. Please if any of you programmer guys find something wrong with it, let me know. So far, it works great

<?php
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

// Get approved comment count
$totalcomments = get_comments_number( $request->get_id() );

// Get all approved comments (offers) for this request
$comments = get_comments( [
    'post_id' => $request->get_id(),
    'status'  => 'approve',
    'orderby' => 'comment_date',
    'order'   => 'ASC',
] );

// Initialize minimum price variable
$min_price = null;

// Loop through comments to find the minimum price
foreach ( $comments as $comment ) {
    $price = get_comment_meta( $comment->comment_ID, 'hp_price', true );
    if ( $price !== '' && is_numeric( $price ) ) {
        $price = floatval( $price );
        if ( is_null( $min_price ) || $price < $min_price ) {
            $min_price = $price;
        }
    }
}
?>
<div class="hp-meta" style="font-size: 0.875em;">
    <time class="hp-listing__created-date" datetime="<?php echo esc_attr( $request->get_created_date() ); ?>">
        <?php printf( hivepress()->translator->get_string( 'added_on_date' ), $request->display_created_date() ); ?>
    </time>
    <br>
    <span style="color: #333;">
        <strong>Number of offers : <?php echo intval( $totalcomments ); ?></strong>
    </span>
    <?php if ( ! is_null( $min_price ) ) : ?>
        <br>
        <span style="color: #333;">
            <strong>Cheapest offer: <?php echo esc_html( number_format( $min_price, 2 ) ); ?> €</strong>
        </span>
    <?php endif; ?>
</div>

1 Like

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