Skip to content

Instantly share code, notes, and snippets.

@hivepress
Created July 23, 2022 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hivepress/f86aaa3e40c939c6851ea2652a02fb8c to your computer and use it in GitHub Desktop.
Save hivepress/f86aaa3e40c939c6851ea2652a02fb8c to your computer and use it in GitHub Desktop.
Add vendor email link to the listing page #hivepress #listings
<?php
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' => [
'vendor_email_link' => [
'type' => 'content',
'content' => '<a href="mailto:' . esc_attr( $listing->get_user__email() ) . '">Contact Vendor</a>',
'_order' => 5,
],
],
],
],
]
)['blocks'];
}
return $blocks;
},
1000,
2
);
@githubsouf
Copy link

how can i add phone number instead of emails

@githubsouf
Copy link

idk why my code isnt working when i try to add phone number from the attribute section :

get_context( 'listing' ); if ( $listing ) { // Get the phone number from the listing attribute $phone_number = trim( $listing->get_attribute( 'phone-num' ) ); // Remove all non-numeric characters from the phone number $phone_number = preg_replace( '/[^0-9]/', '', $phone_number ); // Generate the phone number link $phone_number_link = 'tel:' . $phone_number; $blocks = hivepress()->helper->merge_trees( [ 'blocks' => $blocks ], [ 'blocks' => [ 'listing_actions_primary' => [ 'blocks' => [ 'vendor_phone_link' => [ 'type' => 'content', 'content' => 'Call now', '_order' => 5, ], ], ], ], ] )['blocks']; } return $blocks; }, 1000, 2 );

@hivepress
Copy link
Author

Sorry, there's no simple code snippet for this, but if you created a Phone attribute for vendors this may be possible with customizations. Please try using our community forum, there's a category for dev-related questions https://community.hivepress.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment