Add text field before description field

Hi, I would like to know if it is possible to add a section with note and opinion before the “description” section on my listing.

my brand receive products and I would like my brand to be able to have a section to give a rating and review on backend.

If it’s not too heavy of code, you’ve already provided me with a lot of PHP, I think that’s also why I’m rated F on GTmetrix😅. I’ll see if I can improve the speed and structure of my site to be able to buy the plugins from you: statistics, schedule and connection by FB and Google soon

Please try this PHP snippet

add_filter(
	'hivepress/v1/templates/listing_view_page',
	function( $template ) {
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_content' => [
						'blocks' => [
							'custom_text_above_description' => [
								'type' => 'content',
								'content' => '<p>Your content here</p>',
								'_order' => 55,
							],
						],
					],
				],
			]
		);
	},
	1000
);
1 Like

That’s no good, it has to be customizable for each listing in the backend.

thanks anyway @yevhen

Please try to add a custom listing attribute with the Textarea type and uncheck Allow front-end editing option for this attribute to make it editable only by you when you edit a listing from the WordPress dashboard or check the Allow front-end editing option if you want to give the possibility to listing owner (vendor) to change the value of this attribute. Then please try this PHP snippet. Also, please change get_your_attribute_field_name_or_slug with get_ + your custom attribute slug/field name

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$text = $listing->get_your_attribute_field_name_or_slug();
		
		if(!$text){
			return $blocks;
		}
		
		return hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'page_content' => [
								'blocks' => [
									'custom_text_above_description' => [
										'type' => 'content',
										'content' => '<p>'.$text.'</p>',
										'_order' => 55,
									],
								],
							],
						],
				]
				)['blocks'];
	},
	1000,
	2
);

Thanks that’s great @yevhen

  1. Is it possible to put a “Review” section with rating, instead of a “textarea” attribute? To make our rating sortable.

  2. Will this code slow down my site even more? I already have a very bad loading time and I want to add your statistic extension to start

  1. Sorry, there’s no simple code snippet - this requires advanced customizations.
    If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fwd.cx/hLhc73mQCD9R

  2. I do not think it affects the speed of the site much

1 Like

Ok i will see it soon

I placed the code in the function.php of my child theme, with get_avis_kanazenda (name of my slug) but nothing appears on the listings.

Did I do it wrong