Add a custom button on each listing

Hello team !
I’m quite new to the univers of web dev, and i found your pluggin/theme realy helpfull for a good base.
But now i’m trying to adapt the theme to what i have in mind, and so my first objective is to add a button to all listing, in the main block and in the main page slot. i want the button to be able to do some custom thing, like take the visitor information, and add it to a list in the data base, stuff like this. Juste a button that can fire custom script.

Thx for the help :wink:

PS: sorry for my english, i’m french

Hi,

You can add a button using the attribute listing, please check this sample How to add a WhatsApp button - HivePress Help Center. But note that adding a script and other settings will require custom implementation.

Thx but it seams that when a use créate a listing, they need to do it manualy no ? in my case i want to set a button to all the listing that can’t be editing, and that can run script like
-right the id of the user, the id of the article and a value (number) in a data base table
-add the article in a page, listing all the listing that have been add by the user

I don’t know if the atribute solution can do all of that.
Thx for the quick respond btx :slight_smile:

Hi,

Unfortunately, there’s no such feature, it would require a custom implementation. 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://fvrr.co/32e7LvY

Ok tht so i’m gonna try to make a “extension” that can add all the features that i need.
Also i’m looking for the good hook and files to add my button, but i have some trouble finding it, i want the button to appear on the main block of the listing et on the main page, (were the price is located)

So i’m trying to add just a text for testing purpose in the includes/template listing_view_page (in the page_sidebar précisly), so i’m using the hook hivepress/v1/templates/listing_view_page/blocks it’s that correct?

So my script for testing look like that:

add_filter('hivepress/v1/templates/listing_view_page/blocks', 'test_block', 10, 2);

function test_block($blocks, $template) {
    $blocks['page_sidebar']['blocks']['custom_greeting'] = [
        'type' => 'content',
        'content' => '<div class="custom-greeting">Test</div>',
        '_settings' => ['columns'],
        '_order' => 15,
    ];

    return $blocks;
}

I’m créating a custom plugin btw

So, am I correct or am I going right in the wall ? :confused:

I found this snippet:

add_filter(
	'hivepress/v1/templates/listings_view_page',
	function( $template ) {
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_sidebar' => [
						'blocks' => [
							'custom_name_here' => [
								'type'    => 'content',
								'content' => 'custom text here',
								'_order'  => 123,
							],
						],
					],
				],
			]
		);
	}
);

I put it in my custom plugin, and in a snippet using code snippet, but neither one or the other seams to work

Hi,

Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress

Ok no problem i found a way to do what i want anyway.

So now i have just a small question, i créated an attribute for the listing creation (it’s a value) and i want to save this value in the database, so i can reuse it later for some script. but i can’t find it, i don’t even know if it’s save in the database. can you help me with it ?

Thx btw

Hi,

If it is not a selective attribute, it is stored as a post meta with a hp_ prefix. If it is a selectable attribute, for example, radio checkbox or select, it is stored as custom taxonomy with the hp_ prefix. If you have a listing object, then you can get it this way $listing->get_attributenamehere().

​I hope this is helpful to you.

Thx that good i find what i needed :wink:

Sorry to bother you every time but now i’m having an other request :slight_smile:
i need to prevent user to edit some attribute of there listing, is there an easy way to do that ?

Thx again

Hi,

​Please send more details about this question, and we will do our best to help you.

Ok, so

I have an attribut that allow user to set the price of there item, but i don’t want theme to be able to update the value after the listing is set to public.

I don’t know if it’s enought info, tell me if you need more :wink:

Also i would like to know were are stored the attribute value on the database, i saw that some of the original attribute are stored in the post table, but some that i add aren’t

also just for precise, i can also modify the hivepress plugin files (i know that if i do so i’ll be unable tu update the plugin but it’s not a problem)

Hi,

  1. The easiest option is to mark the attribute as Moderated so that every edit requires the administrator’s confirmation.

  2. The price type attribute is stored in wp_postmeta with the hp_ prefix.

  3. Yes, you can edit, but please note that you need to add changes through external PHP snippets How to add custom code snippets - HivePress Help Center or using a child theme How to create a child theme - HivePress Help Center, otherwise, these changes will be removed after the update from our side.

Hi again

  1. i see, but the problem is that it change the listing statut to draft again, and we don’t have the original value, before the edit, So i think i’m gonna try to completly desable the edit option of all the listings, is there a snippet for that purpous or an easy way ?

  2. i’m talking about the walue of the attribut in each listing

The problem is that the catégorie, the price, and the name of the vendor are in the same column post_excerpt, and i want to use the value of the price, but there are some space in the middle of the value (ex: 651 986) so m’y script can’t read the full value, it just see the first digit (651). so if you have an advice for that that could be realy helpfull :slight_smile:

Hi,

  1. Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress
    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://fvrr.co/32e7LvY

  2. It is displayed in post_excerpt only if you have marked the attribute as indexable (this is necessary for search), and the attribute values (if it is not a selectable attribute) are stored in wp_postmeta.

Ok thx for all, i’ll try for the 1. to find something.