Join our new community forum for support & discussion

Join Now

Home Support General HivePress Custom button per category instead of Reply to listing

Custom button per category instead of Reply to listing

  • Author
    Posts
  • alexif

    Hello!

    Is there any way that the customer reply to listing button can be replaced with for example an affiliate link but only in certain categories?

    Thanks,
    Alex

    yevhen developer

    Please try this PHP snippet. Please just change [1,2,3] with categories where you want to show affiliate link

    add_filter(
    	'hivepress/v1/templates/listing_view_page/blocks',
    	function ($blocks, $template){
    		
    		$listing = $template->get_context('listing');
    		
    		$categories_id = [1,2,3];
    		
    		if($listing && array_intersect((array)$listing->get_categories__id(), $categories_id) ){
    			$blocks = hivepress()->helper->merge_trees(
    					[ 'blocks' => $blocks ],
    					[
    						'blocks' => [
    							'listing_actions_primary' => [
    								'blocks' => [
    									'message_send_link' => [
    										'type'   => 'content',
    									],
    									
    									'custom_affiliate_link' => [
    										'type' => 'content',
    										'content' => '<button type="button" class="button button--primary hp-button--wide" data-component="link" data-url="your_url_here">Custom text here</button>',
    										'_order' => 10,
    									],
    								],
    							],
    						],
    				]
    				)['blocks'];
    		}
    		
    		return $blocks;
    	},
    	1000,
    	2
    );
Viewing 2 posts - 1 through 2 (of 2 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.