Home Support Extensions Messages Hide ‘Send Message’ button from a given category

Hide ‘Send Message’ button from a given category

  • Author
    Posts
  • artshareco

    Hi,

    Is it possible to hide the ‘Send Message’ button from a given category? I use categories as profiles.

    yevhen developer

    Please try using this code snippet to hide the Send Message button from listing pages of some specific categories:

    add_filter(
    	'hivepress/v1/templates/listing_view_page/blocks',
    	function( $blocks, $template ) {
    		$listing = $template->get_context( 'listing' );
    
    		if ( $listing && array_intersect([1,2,3], (array)$listing->get_categories__id() ) {
    			$blocks = hivepress()->helper->merge_trees(
    				[ 'blocks' => $blocks ],
    				[
    					'blocks' => [
    						'message_send_link' => [
    							'type' => 'content',
    						],
    					],
    				]
    			)['blocks'];
    		}
    
    		return $blocks;
    	},
    	1000,
    	2
    );

    You just need to change this part: array_intersect([*categories id which you need to hide button, separate them with comma*], (array)$listing->get_categories__id()

    artshareco

    Hi Yevhen,

    I’ve tried it but I can still see the ‘Send Message’ button in the specific category.

    artshareco

    I used the code snippet below and it worked. Your snippet gave a fatal error because a parenthesis sign was missing. Also, I had to select the IDs of the categories I wanted to keep the ‘Send Message’ button for.

    Thanks for your help!

    
    add_filter(
    	'hivepress/v1/templates/listing_view_page/blocks',
    	function( $blocks, $template ) {
    		$listing = $template->get_context( 'listing' );
    
    		if ( $listing && ! array_intersect( [ 1, 2, 3 ], (array) $listing->get_categories__id() ) ) {
    			$blocks = hivepress()->helper->merge_trees(
    				[ 'blocks' => $blocks ],
    				[
    					'blocks' => [
    						'message_send_link' => [
    							'type' => 'content',
    						],
    					],
    				]
    			)['blocks'];
    		}
    
    		return $blocks;
    	},
    	1000,
    	2
    );
    
    yevhen developer

    Yes, it seems that we missed a parenthesis. Thanks for posting the solution!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.