Add vendor name to listing block

Hello,

I have been reviewed some forum entries like:

But it’s not clear for me the possibility to add or not the vender in the listings block. I am trying to add some code snippet with the variable “$listing->get_user__id()”, but I can’t.

Is it possible to do it with a code snippet similar to this one?

add_filter('hivepress/v1/templates/listing_view_block', function( $template ) {
	return hivepress()->helper->merge_trees($template,	[
				'blocks' => [
					'listing_content' => [
						'blocks' => [
							'custom_text' => [
								'type' => 'content',
								'content' => "$listing->get_user__id()",
								'order' => 15,
							]
						]
					],
				],
			]
		);
	}
);

Thanks and regards,

Hi,

Please provide more details. Do you need to add a vendor name to the listing block? Also, what kind of theme do you use?

Hi,

Yes, I would like to add a vendor name to the listing block. I am trying to get the vendor from the listing and doing the same procedure that is done in this tutorial video which tells the addition of a new button:

# Customizing Templates I HivePress Developer Docs

Theme is HivePress,

Thanks and regards!

Hi!

I finally solved overwritting code in listing-image.php with the following sentence:

<?php echo "Vendor: "; $user = $listing->get_user(); echo $user->get_display_name(); ?>

I don’t know if it is possible doing this with code snippet which is more elegant.

Thanks and best regards,

Hi,

To extract an object from the listing context, you need to use the same hook, but add /blocks at the end, then the second argument of the function is a template, and you can $template->get_context('listing'), and then $listing->get_vendor__name().

Hi!

I finally solved like this:

add_filter(
	'hivepress/v1/templates/listing_view_block/blocks',
	function( $blocks, $template ) {
		$listing = $template->get_context('listing');
		
		if($listing && $listing->get_vendor__name()){
			$blocks = hivepress()->helper->merge_trees(
					[ 'blocks' => $blocks ],
					[
						'blocks' => [
							'listing_details_primary' => [
								'blocks' => [
									'custom_listing_block_description' => [
										'type'    => 'content',
										'content' => '<p style="font-size: 10px;">'.esc_html($listing->get_vendor__name()).'</p>',
										'_order'  => 6,
									],
								],
							],
						],
				]
				)['blocks'];
		}
		
		return $blocks;
	},
	1000,
	2
);

Thanks and best regards,

I have been wanting to do the same! thanks @paperboy

I have upgraded the idea to make the links lead to the vendor profile.

<?php
add_filter(
    'hivepress/v1/templates/listing_view_block/blocks',
    function( $blocks, $template ) {
        $listing = $template->get_context('listing');
        
        if ($listing && $listing->get_vendor()) {
            $vendor = $listing->get_vendor();
            $vendor_slug = $vendor->get_slug();

            // Construct the vendor profile URL using the slug
            $vendor_url = 'https://yousite.com/vendor/' . $vendor_slug . '/';

            $blocks = hivepress()->helper->merge_trees(
                    [ 'blocks' => $blocks ],
                    [
                        'blocks' => [
                            'listing_details_primary' => [
                                'blocks' => [
                                    'custom_listing_block_description' => [
                                        'type'    => 'content',
                                        'content' => '<p style="font-size: 14px;"><a href="' . esc_url($vendor_url) . '">' . esc_html($vendor->get_name()) . '</a></p>',
                                        '_order'  => 6,
                                    ],
                                ],
                            ],
                        ],
                ]
                )['blocks'];
        }
        
        return $blocks;
    },
    1000,
    2
);

Thinking about adding the seller’s photo to make the listings more personal

For anyone visiting this post, you can use this code reference to add customizations anywhere

https://hivepress.github.io/code-reference/files/hivepress-includes-models-class-vendor.html

It looks great! @thefourcraft

I was able to change the listing image to the category image like this:

I think you could modify the child template in the same way, at the beginning or the end of the listing.

Regards!

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