Join our new community forum for support & discussion

Join Now

Home Support Themes ListingHive Contact Button with custom link on Product Page instead of Buy Now or Reply.

Contact Button with custom link on Product Page instead of Buy Now or Reply.

  • Author
    Posts
  • bataffleck

    I want a snippet to add a contact button on every product page with custom link to a form or any other page featuring a contact form to collect customer data like phone no. etc(I’ve already created a page just need a snippet to add a button linking to that page) instead of Buy Now or Reply to listing button, Also if that contact button somehow gives the product ID or page ID of the page it was clicked on, that would be a huge help.

    Thanks.

    yevhen developer

    Please try this PHP snippet. Please save this part ?listing_id='.$listing->get_id() in url as it contains listing ID which you can use by your requirements

    add_filter(
    	'hivepress/v1/templates/listing_view_page/blocks',
    	function( $blocks, $template ) {
    		
    		$listing = $template->get_context('listing');
    		
    		if($listing){
    			$blocks = hivepress()->helper->merge_trees(
    					[ 'blocks' => $blocks ],
    					[
    						'blocks' => [
    							'listing_actions_primary' => [
    								'blocks' => [
    									'custom_icon_print' => [
    										'type' => 'content',
    										'content' => '<button type="button" class="button button--primary hp-button--wide" data-component="link" data-url="your_url_here?listing_id='.$listing->get_id().'">Custom text here</button>',
    										'_order' => 1000,
    									]
    								]
    							],
    						]
    						
    						
    				]
    				)['blocks'];
    		}
    		
    		return $blocks;
    	},
    	1000,
    	2
    );
    bataffleck

    Would you be kind and also tell me on which file do I have to add this snippet ?

    bataffleck

    Sorry to be bothering again and again but one last thing I want is that button to be shown even without the visitor being logged in.

    yevhen developer

    Please try Code Snippets plugin to put this code snippet on your website https://wordpress.org/plugins/code-snippets/

    Yes, this button will be shown for all users

    bataffleck

    Okay Thanks for your support, Sir.

Viewing 6 posts - 1 through 6 (of 6 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.