Hide button if reviewer isn't buyer

We are currently implementing the Review functions, which work quite well; however, we want to limit the review only if both parties have an order.

We get an error once we try to submit a review and we are not a buyer, but how can we check if this is true, so we can hide the button in this case or display a different message.

here is our current implementation:

																<div class="d-flex flex-sm-row flex-column align-items-sm-center align-items-stretch justify-content-between">
																	<?php

																	$args = array(
																		'fields' => array(
																			'listing' => array(
																				'display_type' => 'hidden',
																				'value' => $listing->get_id(),
																			),
																			'text' => array(
																				'attributes' => array(
																					'rows' => 5,
																				),
																			),
																		),
																		'button' => array(
																			'label' => esc_html__('Leistung bewerten', 'finder'),
																			'attributes' => array(
																				'class' => array('btn btn-primary d-block w-100 mb-4 mt-4'),
																			),
																		),
																	);

																	$listing_review = new Review_Submit($args);

																	$modal_id_reference = 'user_login_modal';
																	if (is_user_logged_in()) {
																		$modal_id_reference = 'review_submit';
																	}

																	$modal_content_class = ('car-finder' === $post_style) ? ' bg-dark border-light' : '';
																	$modal_title_class = ('car-finder' === $post_style) ? ' text-light' : '';
																	?>
																	<div class="modal fade listing-single-review-form<?php echo esc_attr('car-finder' === $post_style ? ' finder-form-dark' : ''); ?>" id="review_submit" tabindex="-1" aria-modal="true" role="dialog">
																		<div class="modal-dialog modal-dialog-centered" role="document">
																			<div class="modal-content<?php echo esc_attr($modal_content_class); ?>">
																				<div class="modal-header d-block position-relative border-0 pb-0 px-sm-5 px-4">
																					<h3 class="modal-title mt-4 text-center<?php echo esc_attr($modal_title_class); ?>"><?php esc_html_e('Diese Leistung bewerten', 'finder'); ?></h3>
																					<button class="btn-close position-absolute top-0 end-0 mt-3 me-3<?php echo esc_attr('car-finder' === $post_style ? ' btn-close-white' : ''); ?>" type="button" data-bs-dismiss="modal" aria-label="<?php esc_attr_e('Close', 'finder'); ?>"></button>
																				</div>
																				<div class="modal-body px-sm-5 px-4">
																					<?php echo apply_filters('finder_listing_review_form_output', $listing_review->render()); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
																				</div>
																			</div>
																		</div>
																	</div>
																	<?php
																	$button_class = ('city-guide' === $post_style) ? ' btn btn-outline-primary rounded-pill' : ' btn btn-outline-primary';
																	$button_class = ('car-finder' === $post_style) ? ' btn btn-primary' : $button_class;
																	$author_class = ('car-finder' === $post_style) ? ' text-light' : '';
																	$review_border_class = ('car-finder' === $post_style) ? ' border-light' : '';
																	$review_date_class = ('car-finder' === $post_style) ? ' text-light opacity-50' : ' text-muted';
																	?>
																	<a class="mb-sm-0 mb-3<?php echo esc_attr($button_class); ?>" href="#<?php echo esc_attr($modal_id_reference); ?>" data-bs-toggle="modal" style="z-index: 1">
																		<i class="fi-edit me-1"></i>
																		<?php esc_html_e('Diese Leistung bewerten', 'finder'); ?>
																	</a>
																</div>

Any update on this? Thanks.

Please try to enable the Restrict reviews to buyers setting in HivePress/Settings/Orders

Hey yevhen,

the option is enabled already; however, we can still submit reviews nonetheless.

What we find also strange is that sometimes when we submit a review the review count doesn’t get updated (but the new review shows up) and sometimes the total review count of a vendor also doesn’t get updated.

Is this known?

BR

An update would be appreciated…

I’m sorry for the delay. There’s a known bug related to the option mentioned above, if possible wait for the Marketplace update. If it’s urgent, you can implement this restriction with a custom code snippet, but this requires customizations. Please check how the existing order is checked in the validate_review function in hivepress-marketplace/includes/components/class-marketplace.php

Hope this helps.

Thanks a lot for the reply. Is there an ETA for the marketplace update?

Hi,

Unfortunately, there is no exact timeframe, but we’ll fix this feature as soon as possible.

Alright, your quick-fix (switching back from HPOS) fixed the issues for us.

2 Likes

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