Display discounts on single listing page

Is it possible to display the discount that is set by the vender in the single listing page so the renter can see that if he takes the apartment for longer, he will get a discount?

Thank you for waiting. Please try this PHP code snippet. But please note that it can require further customization. If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function($blocks, $template){
		$listing = $template->get_context('listing');
		
		if(!get_option( 'hp_listing_allow_discounts' ) || !$listing || !$listing->get_discounts()){
			return $blocks;
		}
		
		$output = '';
		
		foreach ( wp_list_sort( $listing->get_discounts(), 'percentage', 'DESC' ) as $discount ) {
			$output .= '<p>Discount for '.esc_html( $discount['quantity'] ).' days is '.esc_html( $discount['percentage'] ).'%</p>';

		}
		
		return hivepress()->template->merge_blocks(
			$blocks,
			[
				'page_sidebar' => [
					'blocks' => [
						'custom_discount_listing_block' => [
							'type' => 'content',
							'content' => $output,
							'_order' => 15,
						],
					],
				],
			],
		);
	},
	1000,
	2
);
1 Like

Thank you so much for the snippet. Can it be perfected to be in the price block, or in the date block? So it should look nice and neat.
See snippet below this is how it is now,

Thank you for waiting. Please try this PHP snippet instead

add_filter(
	'hivepress/v1/forms/booking_make',
	function($args, $form){
		if(!get_option( 'hp_listing_allow_discounts' )){
			return $args;
		}
		
		$booking = $form->get_model();
		
		if(!$booking){
			return $args;
		}
		
		$listing = $booking->get_listing();
		
		if(!$listing || !$listing->get_discounts()){
			return $args;
		}
		
		$output = '';
		
		foreach ( wp_list_sort( $listing->get_discounts(), 'percentage', 'DESC' ) as $discount ) {
			$output .= '<p>Discount for '.esc_html( $discount['quantity'] ).' days is '.esc_html( $discount['percentage'] ).'%</p>';

		}
		
		$args['header'] = $output;
		
		return $args;
	},
	1000,
	2
);
3 Likes

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