Show full Listing title and Listing url for WhatsApp users

Please update this snippet code to add %listing_title% and %listing_url% for users and show current classified listing title and url address in their wahtsapp messenger when click “Chat Via Whatsapp” and Show full Listing Title and full Referred URL of Listing for users and vendor

Like below:

Hello Vendor! I’m sending text for %listing_title% via %listing_url%

This is default snippet for sending Listing URL to WhatsApp chat and need update and adding %listing_title% to below codes, I’ve try but not working:


add_filter(
	'hivepress/v1/models/listing/fields',
	function( $fields, $listing ) {
		foreach ( $fields as $name => $field ) {
			if ( isset( $field['display_template'] ) && strpos( $field['display_template'], '%listing_url%' ) !== false ) {
				$fields[ $name ]['display_template'] = str_replace( '%listing_url%', get_permalink( $listing->get_id() ), $field['display_template'] );
			}
		}

		return $fields;
	},
	1000,
	2
);

Please try this PHP snippet

add_filter(
	'hivepress/v1/models/listing/fields',
	function( $fields, $listing ) {
		foreach ( $fields as $name => $field ) {
			if ( isset( $field['display_template'] ) ) {
				$fields[ $name ]['display_template'] = str_replace( ['%listing_url%', '%listing_title%'], [get_permalink( $listing->get_id()), $listing->get_title()], $field['display_template']);
			}
		}

		return $fields;
	},
	1000,
	2
);

It’s not working yet. only showing listing url but listing title is not show!

Please try this PHP snippet instead

add_filter(
	'hivepress/v1/models/listing/fields',
	function( $fields, $listing ) {
		foreach ( $fields as $name => $field ) {
			if ( isset( $field['display_template'] ) && (strpos($field['display_template'], '%listing_url%') !== false || strpos($field['display_template'], '%listing_title%') !== false) ) {
				$listing_title = str_replace(' ', '+', get_the_title($listing->get_id()));
				$fields[ $name ]['display_template'] = str_replace( ['%listing_url%', '%listing_title%'], [get_permalink( $listing->get_id()), $listing_title], $field['display_template']);
			}
		}

		return $fields;
	},
	1000,
	2
);
2 Likes

Thanks, it’s now working great!

1 Like

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