• Resolved tractanz

    (@tractanz)


    Hi there,

    First off thank you for making such a great plugin available! The issue i’m having is with custom meta fields. I’ve followed steps on the documentation page – https://wpstorelocator.co/document/add-custom-meta-data-to-store-locations/

    The error I’m getting is one off my custom meta fields is undefined, the below is how I’ve implemented in my theme:

    // -- Listing template meta fields
    add_filter( 'wpsl_meta_box_fields', 'custom_meta_box_fields' );
    function custom_meta_box_fields( $meta_fields ) {
        $meta_fields[__( 'Additional Information', 'wpsl' )] = array(
            'phone' => array(
                'label' => __( 'Phone', 'wpsl' )
            ),
            'email' => array(
                'label' => __( 'Email', 'wpsl' )
            ),
            'website_url' => array(
                'label' => __( 'Website', 'wpsl' )
            ),
            'google_map_url' => array(
                'label' => __( 'Google Map URL', 'wpsl' )
            )
        );
        return $meta_fields;
    }
    
    // -- Listing template meta fields json
    add_filter( 'wpsl_frontend_meta_fields', 'custom_frontend_meta_fields' );
    function custom_frontend_meta_fields( $store_fields ) {
        $store_fields['wpsl_google_map_url'] = array( 
            'name' => 'google_map_url',
            'type' => 'url'
        );
        $store_fields['wpsl_website_url'] = array( 
            'name' => 'website_url',
            'type' => 'url'
        );
        return $store_fields;
    }
    
    // -- Listing template
    add_filter( 'wpsl_listing_template', 'custom_listing_template' );
    function custom_listing_template() {
        global $wpsl_settings;
        $listing_template = '<li data-store-id="<%= id %>">' . "\r\n";
        $listing_template .= "\t\t" . '<div>' . "\r\n";
        $listing_template .= "\t\t\t" . '<p class="address"><%= thumb %>' . "\r\n";
        $listing_template .= "\t\t\t\t" . '<span class="title">' . wpsl_store_header_template( 'listing' ) . '</span>' . "\r\n";
        $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";
        $listing_template .= "\t\t\t\t" . '<span class="wpsl-country"><%= country %></span>' . "\r\n";
        $listing_template .= "\t\t\t" . '</p>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% if ( website_url ) { %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<p class="website"><a href="<%= website_url %>" target="_blank">Website: <%= website_url %></a></p>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% if ( phone ) { %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<p class="phone"><a href="tel:<%= phone %>">Phone: <%= phone %></a></p>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% if ( google_map_url ) { %>' . "\r\n";
        $listing_template .= "\t\t\t" . '<p class="directions"><a href="<%= google_map_url %>" target="_blank">' . __( 'Directions', 'wpsl' ) . '</a></p>' . "\r\n";
        $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $listing_template .= "\t\t" . '</div>' . "\r\n";
        // Check if we need to show the distance.
        // if ( !$wpsl_settings['hide_distance'] ) {
        //     $listing_template .= "\t\t" . '<%= distance %> ' . esc_html( $wpsl_settings['distance_unit'] ) . '' . "\r\n";
        // }
        //$listing_template .= "\t\t" . '<%= createDirectionUrl() %>' . "\r\n"; 
        $listing_template .= "\t" . '</li>' . "\r\n";
        return $listing_template;
    }
    
    // -- Location template meta fields
    add_filter( 'wpsl_info_window_template', 'custom_info_window_template' );
    function custom_info_window_template() {
        global $wpsl_settings;
        $info_window_template = '<div data-store-id="<%= id %>" class="wpsl-info-window">' . "\r\n";
        $info_window_template .= "\t\t" . '<div>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<p class="address"><%= thumb %>' . "\r\n";
        $info_window_template .= "\t\t\t\t" . '<span class="title">' . wpsl_store_header_template( 'listing' ) . '</span>' . "\r\n";
        $info_window_template .= "\t\t\t\t" . '<span class="wpsl-street"><%= address %></span>' . "\r\n";
        $info_window_template .= "\t\t\t\t" . '<% if ( address2 ) { %>' . "\r\n";
        $info_window_template .= "\t\t\t\t" . '<span class="wpsl-street"><%= address2 %></span>' . "\r\n";
        $info_window_template .= "\t\t\t\t" . '<% } %>' . "\r\n";
        $info_window_template .= "\t\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n";
        $info_window_template .= "\t\t\t\t" . '<span class="wpsl-country"><%= country %></span>' . "\r\n";
        $info_window_template .= "\t\t\t" . '</p>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% if ( website_url ) { %>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<p class="website"><a href="<%= website_url %>" target="_blank">Website: <%= website_url %></a></p>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% if ( phone ) { %>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<p class="phone"><a href="tel:<%= phone %>">Phone: <%= phone %></a></p>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% if ( google_map_url ) { %>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<p class="directions"><a href="<%= google_map_url %>" target="_blank">' . __( 'Directions', 'wpsl' ) . '</a></p>' . "\r\n";
        $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
        $info_window_template .= "\t\t" . '</div>' . "\r\n";
        //$info_window_template .= "\t\t" . '<%= createDirectionUrl() %>' . "\r\n"; 
        $info_window_template .= "\t" . '</div>' . "\r\n";
        return $info_window_template;
    }

    I think the issue is caused by the function storing the meta fields to json? I would appreciate any help getting this working correctly!

    Cheers

Viewing 1 replies (of 1 total)
  • Thread Starter tractanz

    (@tractanz)

    Apologies, my issue is now all sorted. Clearing the WPSL transients was the fix.

    Thanks again for the plugin!

    • This reply was modified 1 year, 10 months ago by tractanz.
Viewing 1 replies (of 1 total)
  • The topic ‘Meta Field Undefined’ is closed to new replies.