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
);
1 Like

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

Please use the Code Snippets plugin to add and manage custom PHP code snippets Code Snippets – WordPress plugin | WordPress.org

I must put the code in fonction.php of my chil theme?

if so, it’s already install here, with “get_ + avis_kanazenda” (my slug of textarea) but no section appear on the listing🤨

Please follow these instructions How to add custom code snippets - HivePress Help Center and make sure that the code snippet is added correctly, also check the attribute name - this snippet works fine when I test it locally

I found why not appear, i’ve forget “()” at the end of "get_":sweat_smile:

Thank you, work good

hello yehen, I am currently trying to put my texts in the area. But the text formatting doesn’t wrap anything, everything is attached. impossible to find a solution, you know why it does that?

Please try to use this PHP snippet instead if you put this text with this snippet which was provided above

add_filter(
	'hivepress/v1/templates/listing_view_page/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
		$text = $listing->display_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
);

it’s the same snippet.

My problem is that no spaces are displayed. All text is continuous.

it should display like this:

This would require further customizations, if you’re familiar with PHP/HTML basics please try adding <br> tag before or after the <p>...</p>, this will add more space using line breaks. If further customizations beyond the available options are required please consider hiring a developer via Fiverr https://fwd.cx/hLhc73mQCD9R

I’ve already do that with html

Code is:

<hr />
<h2>TITLE</h2>
<p>Le 9 Mars 2022.</p>
&nbsp
<p><strong>Expédition/Livraison:</strong> Rapide<br>
<strong>Qualité des produits:</strong> Bon</p>
&nbsp
<p><strong>NOTRE AVIS:</strong> toujours à la recherche de bon produits à proposer à ses clients, Hunter Family CBD à su nous faire plaisir notamment avec la Legendary, la Cali et la Big Buddha qui ont été réellement un coup de cœur. Nous avons cependant moins préféré le hash Venom et la Purple. Avec un PDG fort sympathique, toujours à l'écoute des demandes de ses fans, vous apprécierez très certainement cette jeune marque en pleine évolution.</p>

<hr />
&nbsp

Thanks for sharing, you can also try using the most recent snippet suggested above (notice that it uses “display” instead of “get” like in the previous one).

1 Like

actually, I hadn’t noticed the change “get” to “display”. it works great thank you @yevhen @ihor

1 Like

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