Adjusting Custom Field Placement on Vendor Profile Page

Hi,

Could you please guide me on how to reposition a custom attribute from the left side to the right side on the vendor profile page? Specifically, I want to place it either below or above the default description field. Could you please provide a code snippet or some guidelines? I have already managed to implement a custom field on the listing page, but I haven’t figured this one out yet.

I am also interested in this !

Actually here is what I did so far :
Override the Vendor template (HivePress > Template).
Put some columns.
And add a shortcode to return the description, or simple (text) attributes via shortcodes.

Something like this would return the description from the vendor using this shortcode [vendor_desc]

function hivepress_vendor_description_shortcode($atts) {
    // Get the current post ID (context from URL)
    $post_id = get_the_ID();
    // Fetch the vendor post object
    $vendor_post = get_post($post_id);

    if (!$vendor_post || $vendor_post->post_type !== 'hp_vendor') {
        return __('Invalid vendor.', 'text-domain');
    }

    // Get the vendor description
    $description = $vendor_post->post_content;
	return $description; 
}

// Register the shortcode
add_shortcode('vendor_desc', 'hivepress_vendor_description_shortcode');

I know this probably not the best way according to hivepress paradigm (MVC), but I am new to this, and I find it somewhat overly complicated.

And I can’t retrieve multiple values fields anyway.
I have a “mobility” attribute holding two possible values (from checkboxes).

I would appreciate some hindsights. I spent much time on this before crying for help.

Cheers !

3 Likes

Hi,

Sorry for the late reply. Yes, the best option is to overwrite the vendor template in HivePress > Templates, and then you can move the blocks as you like.

Your reply was not late at all. :smile:

However, even if I use the templates, how do I access my attributes ?
There’s no built-in block for that, as far as I know, since the are custom ones.

That’s why I relied on custom-made shortcode, but I can’t find a way to access the most complicated (multiple values) ones. Where there is a will, there is a way.

Please advise.

Cheers !

The more I play around with HivePress ecosystem, the more I am amazed.
There are actually some blocks for that :

You’d just have to assign your attributes to these block areas (primary, secondary, ternary) beforehand. Brilliant.

Thanks !

2 Likes

Thank you for your response, this is a nice workaround. I have created a template, but since I have two types of vendors, is there a possibility to target the Vendor1 profiles with the custom field used in the PHP snippet below?

add_filter(
	'hivepress/v1/templates/vendor_view_page',
	function( $template, $object ) {
		$vendor = hivepress()->request->get_context( 'vendor' );

		if ( $vendor ) {
			$template = hivepress()->helper->merge_trees(
				$template,
				[
					'blocks' => [
						'page_content' => [
							'blocks' => [
								'demo_custom_field' => [
									'type'    => 'content',
									'content' => $vendor->get_my_custom_field(),
									'_order'  => 1,
								],
							],
						],
					],
				]
			);
		}

		return $template;
	},
	10,
	2
);

I’m sorry for the delay. The recent code snippet you posted should be functional, if you use vendor categories as types, please try this code snippet to make different changes to the vendor page based on the vendor type (replace 123 with the category ID):

add_filter(
	'hivepress/v1/templates/vendor_view_page',
	function( $template, $object ) {
		$vendor = hivepress()->request->get_context( 'vendor' );

		if ( $vendor ) {
			if ( in_array( 123, $vendor->get_categories__id() ) ) {
				$template = hivepress()->template->merge_blocks(
					$template,
					[
						'page_content' => [
							'blocks' => [
								'demo_custom_field' => [
									'type'    => 'content',
									'content' => $vendor->get_my_custom_field(),
									'_order'  => 1,
								],
							],
						],
					]
				);
			} else {
				// other vendor type
			}
		}

		return $template;
	},
	10,
	2
);

Hope this helps

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