This is possible, are you comfortable with code, and do you have the permalink option enabled?
I have hired a developer to help me with changes to my website, so coding is not an issue.
I don’t think the permalink option is enabled but I can enable it. The links are going to be to Woocommerce product pages so I’m not sure if I need permalinks.
Please let me know how it can be done and I will pass on the information to my dev to test it.
Thanks for all your help!
So how to do this is by using the wpsl_listing_template filter to overwrite the existing search results template, and wrap the whole content inside the li in a link.
A very simplified version is this.
$listing_template = '<li data-store-id="<%= id %>">' . "\r\n";
$listing_template = '<a href="<%= url %>">' . "\r\n";
$listing_template = 'rest of the content' . "\r\n";
$listing_template = '</a>' . "\r\n";
$listing_template = '</li>' . "\r\n";
-
This reply was modified 5 years, 11 months ago by
Tijmen Smit.
-
This reply was modified 5 years, 11 months ago by
Tijmen Smit.
-
This reply was modified 5 years, 11 months ago by
Tijmen Smit.
Hi Tijmen,
My developer has tried the above solution with the following code but it would not work:
$listing_template = ‘<li data-store-id=”<%= id %>”>’ . “\r\n”;
$listing_template .= ‘“>’ . “\r\n”;
$listing_template .= “\t\t” . ‘<div class=”wpsl-store-location”>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<p><%= thumb %>’ . “\r\n”;
$listing_template .= “\t\t\t\t” . wpsl_store_header_template( ‘listing’ ) . “\r\n”; // Check which header format we use
$listing_template .= “\t\t\t\t” . ‘<span class=”wpsl-street”><%= address %></span>’ . “\r\n”;
$listing_template .= “\t\t\t\t” . ‘<% if ( address2 ) { %>’ . “\r\n”;
$listing_template .= “\t\t\t\t” . ‘<span class=”wpsl-street”><%= address2 %></span>’ . “\r\n”;
$listing_template .= “\t\t\t\t” . ‘<% } %>’ . “\r\n”;
$listing_template .= “\t\t\t\t” . ‘<span>’ . wpsl_address_format_placeholders() . ‘</span>’ . “\r\n”; // Use the correct address format
if ( !$wpsl_settings[‘hide_country’] ) {
$listing_template .= “\t\t\t\t” . ‘<span class=”wpsl-country”><%= country %></span>’ . “\r\n”;
}
$listing_template .= “\t\t\t” . ‘</p>’ . “\r\n”;
// Show the phone, fax or email data if they exist.
if ( $wpsl_settings[‘show_contact_details’] ) {
$listing_template .= “\t\t\t” . ‘<p class=”wpsl-contact-details”>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<% if ( phone ) { %>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<span>‘ . esc_html( $wpsl->i18n->get_translation( ‘phone_label’, __( ‘Phone’, ‘wpsl’ ) ) ) . ‘: <%= formatPhoneNumber( phone ) %></span>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<% } %>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<% if ( fax ) { %>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<span>‘ . esc_html( $wpsl->i18n->get_translation( ‘fax_label’, __( ‘Fax’, ‘wpsl’ ) ) ) . ‘: <%= fax %></span>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<% } %>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<% if ( email ) { %>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<span>‘ . esc_html( $wpsl->i18n->get_translation( ’email_label’, __( ‘Email’, ‘wpsl’ ) ) ) . ‘: <%= formatEmail( email ) %></span>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘<% } %>’ . “\r\n”;
$listing_template .= “\t\t\t” . ‘</p>’ . “\r\n”;
}
$listing_template .= “\t\t\t” . wpsl_more_info_template() . “\r\n”; // Check if we need to show the ‘More Info’ link and info
$listing_template .= “\t\t” . ‘</div>’ . “\r\n”;
$listing_template .= “\t\t” . ‘<div class=”wpsl-direction-wrap”>’ . “\r\n”;
if ( !$wpsl_settings[‘hide_distance’] ) {
$listing_template .= “\t\t\t” . ‘<%= distance %> ‘ . esc_html( wpsl_get_distance_unit() ) . ” . “\r\n”;
}
$listing_template .= “\t\t\t” . ‘<%= createDirectionUrl() %>’ . “\r\n”;
$listing_template .= “\t\t” . ‘</div>’ . “\r\n”;
$listing_template .= “\t\t” . ‘‘ . “\r\n”;
$listing_template .= “\t” . ‘‘;
Could you let me know what else we could try? Thanks for all your help so far
<li data-store-id=”116″>
<div class=”wpsl-store-location”>
<p>
Barbershop 1
<span class=”wpsl-street”>266 Central Road</span>
<span>Morden Sm4 5rg</span>
</p>
<p class=”wpsl-contact-details”>
</p>
</div>
<div class=”wpsl-direction-wrap”>
</div>
<li data-store-id=”118″>
<div class=”wpsl-store-location”>
<p>
Barber shop 2
<span class=”wpsl-street”>266 Central Road</span>
<span>Morden Sm4 5rg</span>
</p>
<p class=”wpsl-contact-details”>
</p>
</div>
<div class=”wpsl-direction-wrap”>
</div>
Could you post the code in a gist, since it looks broken now.
That URL goes to a 404 for me. Maybe it’s a private gist?
My Github account has been flagged for some reason.
Here is the PHP(?) code: https://pastiebin.com/5e9c470929cbd#&togetherjs=oLq308SFaC
Here is the HTML code: https://pastiebin.com/5e9c462a0e372#&togetherjs=oLq308SFaC
Hopefully, that works.
Hi @tijmensmit,
I just wanted to know if you were able to see the code I sent?
Thanks
Sorry for late response, I see that indeed won’t work what I initially suggested. You have links inside links which won’t work.
Only way I can think of is to first make the cursor show a pointer when it hovers over the list items.
Use ajaxComplete to run code after a search is complete from a custom JS file that listens for clicks on the li element. If so, grab the value from the url field and redirect the user there with JS.
Hi Tijmen,
Thank you for your response. The developer managed to figure out a solution using JS.
Thanks