Add category to the vendor page

Hello,
Is there a way to add the category for the vendor page like in the code below?

Preformatted text

add_filter(
    'hivepress/v1/templates/vendor_view_block/blocks',
    function($blocks, $template){
        $vendor = $template->get_context('vendor');
        if(!$vendor || !$vendor->get_categories()){
            return $blocks;
        }      
        $output = '';
        foreach ( $vendor->get_categories() as $category ){
            $output .= '<div style="margin-top: -15px; margin-bottom: 10px; font-size: 20px;">'.esc_html( $category->get_name() ).'</div>';
        }
        return hivepress()->helper->merge_trees(
            [ 'blocks' => $blocks ],
            [
                'blocks' => [
                    'vendor_content' => [
                        'blocks' => [
                            'custom_vendor_categories' => [
                                'type'   => 'content',
                                'content'  => $output,
                                '_order' => 21,
                            ],
                        ],
                    ],
                ],
            ]
        )['blocks'];
    },
    1000,
    2
);

Hi,

If you are familiar with coding, we recommend overwriting the template parts using this doc: How to override template parts - HivePress Help Center. You can overwrite the vendor name and add HTML code to it, for example, copy the part with categories from the listing template and replace all the words listing with vendor.

The code works in the blocks, but not in the vendors page. How can I fix this?

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

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, but there is no way to just modify the snippet code?

Hi,

If you are familiar with the code, then yes, you can modify this PHP snippet.

Would you please help me on this?

Hi,

Sorry, we cannot provide general guidance here, as this would require a detailed code review and testing, which is unfortunately not within our support scope.

Could you just tell me what is the includes/template directory that I have to modify the section attached?


I tried this code but it’s not working:

add_action('init', function() {
    add_filter(
        'hivepress/v1/templates/listing_view_page/blocks',
        function($blocks, $template) {
            $vendor = $template->get_context('vendor');
            if (!$vendor || !$vendor->get_categories()) {
                return $blocks;
            }
            
            $output = '';
            foreach ($vendor->get_categories() as $category) {
                $output .= '<div style="margin-top: 10px; margin-bottom: 10px; font-size: 20px;">' . esc_html($category->get_name()) . '</div>';
            }

            $blocks['page_sidebar']['blocks']['vendor_summary']['blocks']['vendor_name']['blocks']['custom_vendor_categories'] = [
                'type'    => 'content',
                'content' => $output,
                '_order'  => 15, // Inseriamo dopo il nome
            ];

            return $blocks;
        },
        1000,
        2
    );
});

Hi,

If you purchased a theme or extension, please enter the license key in the forum profile settings, this will enable the Premium Support badge and ensure a 24-hour turnaround time.

Hello, I have entered the license key.

Hi,

Unfortunately, there is no simple PHP snippet for this, it will require advanced customization. If you are familiar with coding, we can provide general guidance. If you are not familiar with coding, we recommend that you consider hiring experts: Customization | HivePress

Yes, I’m. Could you please provide general guidance?

Please check the template part which renders listing categories here hivepress/templates/listing/view/listing-categories.php at master · hivepress/hivepress · GitHub You can copy it, creating a new template part in the child theme (or copy HTML and simply override one of the existing template parts, e.g. the vendor name or description if you want to show categories near these elements), just changing “listing” to “vendor” in this HTML. You can check an example here https://www.youtube.com/watch?v=LkojYp-8uwY

Hope this helps.

Hello, It works! thank you very much!!!

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