• Hello,

    I am using below provided custom code but it is not displaying featured image in the info window.

    // ✅ Add thumbnail URL to the store data passed to JS
    add_filter(‘wpsl_frontend_store_data’, function($store_data, $store_id) {
    $thumbnail_url = wp_get_attachment_url(get_post_thumbnail_id($store_id));
    $store_data[‘post_thumbnail_url’] = $thumbnail_url ? $thumbnail_url : ”;
    return $store_data;
    }, 10, 2);

    // ✅ Customize Info Window Template
    add_filter(‘wpsl_info_window_template’, ‘custom_info_window_template’);
    function custom_info_window_template() {
    global $wpsl_settings, $wpsl;

    $info_window_template = '<div data-store-id="<%= id %>" class="wpsl-info-window">' . "\r\n";
    
    // Thumbnail
    $info_window_template .= "\t\t\t" . '<% if ( typeof post_thumbnail_url !== "undefined" && post_thumbnail_url ) { %>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<img src="<%= post_thumbnail_url %>" alt="Store Image"/>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
    
    // Address
    $info_window_template .= "\t\t" . '<p>' . "\r\n";
    $info_window_template .= "\t\t\t" . wpsl_store_header_template() . "\r\n";
    $info_window_template .= "\t\t\t" . '<span><%= address %></span>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<% if ( address2 ) { %>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<span><%= address2 %></span>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n";
    $info_window_template .= "\t\t" . '</p>' . "\r\n";
    
    // Phone
    $info_window_template .= "\t\t" . '<% if ( phone ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html($wpsl->i18n->get_translation('phone_label', __('Phone', 'wpsl'))) . '</strong>: <%= formatPhoneNumber( phone ) %></span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    
    // Fax
    $info_window_template .= "\t\t" . '<% if ( fax ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html($wpsl->i18n->get_translation('fax_label', __('Fax', 'wpsl'))) . '</strong>: <%= fax %></span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    
    // Email
    $info_window_template .= "\t\t" . '<% if ( email ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html($wpsl->i18n->get_translation('email_label', __('Email', 'wpsl'))) . '</strong>: <%= formatEmail( email ) %></span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    
    // Example: Custom static text
    $info_window_template .= "\t\t" . '<p>Closed Open</p>' . "\r\n";
    
    // Opening Hours
    if (!$wpsl_settings['hide_hours']) {
        $info_window_template .= "\t\t\t" . '<% if ( hours ) { %>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<p><%= hours %></p>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
    }
    
    // Actions (Directions, More Info, etc.)
    $info_window_template .= "\t\t" . '<%= createInfoWindowActions( id ) %>' . "\r\n";
    $info_window_template .= "\t" . '</div>' . "\r\n";
    
    return $info_window_template;

    }


    Please let me know if you have any idea about this issue.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter harshpatel1412

    (@harshpatel1412)

    Additionally can you please also tell me how to customize single detail page of the post in this plugin?

    Thank you.

    Hi there, thanks for writing.

    On a first look, you should use this code snippet for sending the featured image url to the frontend:

    add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
    
    function custom_store_meta( $store_meta, $store_id ) {
        
        $url = get_the_post_thumbnail_url( $store_id, 'medium' );
        $store_meta['post_thumbnail_url'] = $url;
    
        return $store_meta;
    }

    Please try that out and let us know if that does not work for you.
    Best regards,

    Thread Starter harshpatel1412

    (@harshpatel1412)

    Hello @farroyob,

    Thank you for your reply, I have tried to implement the code you have provided but the featured image is still not getting displayed.

    Below provided is my code.
    Please let me know where I am making mistake.

    Thank you.

    // ==============================
    // 1. Add thumbnail URL to store data
    // ==============================
    add_filter( ‘wpsl_store_meta’, ‘custom_store_meta’, 10, 2 );

    function custom_store_meta( $store_meta, $store_id ) {

    $url = get_the_post_thumbnail_url( $store_id, 'medium' );
    $store_meta['post_thumbnail_url'] = $url;
    
    return $store_meta;

    }

    // ==============================
    // 2. Customize Info Window Template
    // ==============================
    add_filter(‘wpsl_info_window_template’, ‘custom_info_window_template’);
    function custom_info_window_template() {
    global $wpsl_settings, $wpsl;

    $info_window_template  = '<div data-store-id="<%= id %>" class="wpsl-info-window">' . "\r\n";
    
    // Thumbnail
    $template = '<div data-store-id="<%= id %>" class="wpsl-info-window">';
    $template .= '<img src="<%= post_thumbnail_url %>" alt="Store Image" style="max-width:100%; height:auto;"/>';
    $template .= '<p><%= address %></p>';
    $template .= '</div>';
    
    // Address
    $info_window_template .= "\t\t" . '<p>' . "\r\n";
    $info_window_template .= "\t\t\t" . wpsl_store_header_template() . "\r\n";
    $info_window_template .= "\t\t\t" . '<span><%= address %></span>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<% if ( address2 ) { %>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<span><%= address2 %></span>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n";
    $info_window_template .= "\t\t" . '</p>' . "\r\n";
    
    // Phone
    $info_window_template .= "\t\t" . '<% if ( phone ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html($wpsl->i18n->get_translation('phone_label', __('Phone', 'wpsl'))) . '</strong>: <%= formatPhoneNumber( phone ) %></span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    
    // Fax
    $info_window_template .= "\t\t" . '<% if ( fax ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html($wpsl->i18n->get_translation('fax_label', __('Fax', 'wpsl'))) . '</strong>: <%= fax %></span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    
    // Email
    $info_window_template .= "\t\t" . '<% if ( email ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html($wpsl->i18n->get_translation('email_label', __('Email', 'wpsl'))) . '</strong>: <%= formatEmail( email ) %></span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    
    // ==============================
    // Opening Hours (Dropdown Toggle)
    // ==============================
    if ( ! $wpsl_settings['hide_hours'] ) {
        $info_window_template .= "\t\t\t" . '<% if ( hours ) { %>' . "\r\n";
        $info_window_template .= '
            <div class="wpsl-hours-dropdown">
                <button type="button" class="wpsl-hours-toggle">Opening Hours ▼</button>
                <div class="wpsl-hours-content" style="display:none;">
                    <%= hours %>
                </div>
            </div>
        ' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
    }
    
    // Actions (Directions, More Info, etc.)
    $info_window_template .= "\t\t" . '<%= createInfoWindowActions( id ) %>' . "\r\n";
    $info_window_template .= "\t" . '</div>' . "\r\n";
    
    return $info_window_template;

    }

    Hi again,

    Sometimes, especially if you make changes to the templates, it helps if you go to the Wp Store Locator settings page, scroll to the bottom and click the “Clear store locator transient cache” button. I hope that does the trick, let me know otherwise.

    Regards,

    Thread Starter harshpatel1412

    (@harshpatel1412)

    Hello @farroyob,

    Thank you for your reply, I have done clearing the cache but still the image is not getting displayed.

    Please let me know if you have any other solution.

    Thank you.

    Hi again, thanks for getting back.

    Maybe if you could write us a support ticket so we can have a more detailed look at your issue, we could figure it out.

    Best regards,

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Featured image not getting displayed ibn’ is closed to new replies.