Created
July 23, 2022 23:36
-
-
Save hivepress/f86aaa3e40c939c6851ea2652a02fb8c to your computer and use it in GitHub Desktop.
Add vendor email link to the listing page #hivepress #listings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
); |
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 );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
how can i add phone number instead of emails