I need review button in the listing block

Hi, I recently purchased hivepress for a client. I need help moving the review button from the listing view page to the listing block, as my website will probably not use the listing view page.

I figured out how to move the review button to the listing block primary area via code snippet, however, when I click on it, it does not open. Any guidance on the code snippet to fix it would be extremely necessary for my project. Thanks!

Hi,

Please send us a code snippet, and we will try to help.

Thanks. Here it is. I noticed when I click on the write a review button, the web browser is displaying a # at the end of the address. I tried to write another code to circumvent that but it was not accepted by the code snippet plugin. Really hoping to get it accomplished via simple code snippet, instead of having to go into child theme. Much appreciated your help!

add_filter(
    'hivepress/v1/templates/listing_view_block/blocks',
    function ($blocks, $template) {
        $review_link = '<a href="#review_submit_modal" class="hp-listing__action hp-listing__action--review hp-link"><i class="hp-icon fas fa-star"></i><span>Write a Review</span></a>';

        return hivepress()->helper->merge_trees(
            ['blocks' => $blocks],
            [
                'blocks' => [
                    'listing_actions_primary' => [
                        'blocks' => [
                            'review_link' => [
                                'type'   => 'content',
                                'content'  => $review_link,
                                '_order' => 30,
                            ],
                        ],
                    ],
                ],
            ]
        )['blocks'];
    },
    1000,
    2
);

Please try this PHP code snippet

add_filter(
    'hivepress/v1/templates/listing_view_block/blocks',
    function ($blocks, $template) {
		$listing = $template->get_context('listing');
		
		if(!$listing){
			return $blocks;
		}
		
        $review_link = '<a href="#review_submit_modal_'.$listing->get_id().'" class="hp-listing__action hp-listing__action--review hp-link"><i class="hp-icon fas fa-star"></i><span>Write a Review</span></a>';
		
		if(!is_user_logged_in()){
			$review_link = '<a href="#user_login_modal" class="hp-listing__action hp-listing__action--review hp-link"><i class="hp-icon fas fa-star"></i><span>Write a Review</span></a>';
		}

        return hivepress()->helper->merge_trees(
            ['blocks' => $blocks],
            [
                'blocks' => [
                    'listing_actions_primary' => [
                        'blocks' => [
							'review_submit_modal_'.$listing->get_id() => [
								'type'        => 'modal',
								'title'       => 'Write a Review',
								'_capability' => 'read',
								'_order'      => 5,

								'blocks'      => [
									'review_submit_form' => [
										'type'   => 'review_submit_form',
										'_order' => 10,
									],
								],
							],
                            'review_link' => [
                                'type'   => 'content',
                                'content'  => $review_link,
                                '_order' => 30,
                            ],
                        ],
                    ],
                ],
            ]
        )['blocks'];
    },
    1000,
    2
);
1 Like

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