Call Now Button code

I have no coding knowledge, please help me to edit below code.
my attribute name is “Phone Number” & slug Name is “contact”
i tried but its not working

add_filter(
    'hivepress/v1/templates/listing_view_page/blocks',
    function( $blocks, $template ) {
        // Get the current listing
        $listing = $template->get_context( 'listing' );

        // Check if a listing exists
        if ( $listing ) {
            // Get the phone number from the listing attribute
			$phone_number = '';
			foreach ( $listing->_get_fields( 'view_page_primary' ) as $field ) {
				if ( $field->get_slug() === 'phone-num' ) {
					$phone_number = $field->get_value();
					break;
				}
			}
			
			if ( empty( $phone_number ) ) {
				// Handle error: phone number attribute is empty or doesn't exist
				// For example: return an error message or use a default phone number
				$phone_number = '555-5555';
			}
			
			// 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;

            // Add the new block to the listing_actions_primary block
            $blocks = hivepress()->helper->merge_trees(
                [ 'blocks' => $blocks ],
                [
                    'blocks' => [
                        'listing_actions_primary' => [
                            'blocks' => [
                                'vendor_phone_link' => [
                                    'type'    => 'content',
                                    'content' => '<a href="' . esc_attr( $phone_number_link ) . '"><button type="button" class="hp-listing__action hp-listing__action--call button button--primary button--large" style="background-color: green; color: white;">   Contact  Now   </button></a>',
                                    '_order'  => 5,
                                ],
                                'second_button' => [
                                    'type'    => 'content',
                                    'content' => '<button type="button" class="hp-listing__action hp-listing__action--other button button--primary button--large" style="background-color: white; color: black; pointer-events: none;"> Or </button>',
                                    '_order'  => 6,
                                ],
                            ],
                        ],
                    ],
                ]
            )['blocks'];
        }
        return $blocks;
    },
    1000,
    2
);

please edit and provide code. thank you

Hi,

Sorry for the inconvenience, but customization is beyond our support scope - it includes fixing bugs and guidance about the available features Support Policy | HivePress

If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.