• Hi,

    I created a news tab in the Store Details area called ‘Buoni spesa’. It is a textarea and I would want it to show in the listing area.

    It’s not working with this code. I thing there’s something wrong in the frontend code, but I cant find out what’s wrong.
    Could you please help me?

    /*tab buono spesa in wpsl*/
    /*backend php*/
    add_filter( ‘wpsl_meta_box_fields’, ‘custom_meta_box_fields’ );

    function custom_meta_box_fields( $meta_fields ) {

    $meta_fields[__( ‘Buono spesa’, ‘wpsl’ )] = array(
    ‘buono-spesa_textarea’ => array(
    ‘label’ => __( ‘Buono spesa’, ‘wpsl’ )
    )
    );

    return $meta_fields;
    }
    /*backend json*/
    add_filter( ‘wpsl_frontend_meta_fields’, ‘custom_frontend_meta_fields’ );

    function custom_frontend_meta_fields( $store_fields ) {

    $store_fields[‘wpsl_buono-spesa_textarea’] = array(
    ‘name’ => ‘buono-spesa_textarea’,
    ‘type’ => ‘textarea’
    );

    return $store_fields;
    }
    /*frontend*/
    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><%= thumb %>’ . “\r\n”;
    $listing_template .= “\t\t\t\t” . wpsl_store_header_template( ‘listing’ ) . “\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”;

    // Check if the ‘buono-spesa_textarea’ contains data before including it.
    $listing_template .= “\t\t\t” . ‘<% if ( buono-spesa_textarea ) { %>’ . “\r\n”;
    $listing_template .= “\t\t\t” . ‘<p>“>’ . __( ‘Buono spesa’, ‘wpsl’ ) . ‘</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” . ‘‘ . “\r\n”;

    return $listing_template;
    }

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    The code is a bit broken, but your are including <%= buono-spesa_textarea %> in the template?

    In the future please put code snippets here, this makes sure it renders correctly.

    Thread Starter valci1

    (@valci1)

    Hi Tijmen,

    here it is:

    https://gist.github.com/ValeriaCurseri/bac13790d1ab8b2e5e4d5271f27c7a60

    Could you please tell me what’s wrong?

    Thank you so much!

    • This reply was modified 4 years, 11 months ago by valci1.
    Plugin Author Tijmen Smit

    (@tijmensmit)

    It does show up for me with that code.

    Can you try to flush the transient cache on the WPSL settings page ( tools section ). Are you using any caching plugins? If so also flush that cache.

    Thread Starter valci1

    (@valci1)

    Hi Tijmen,

    I cancelled the cache but nothing changed.

    The problem is that as soon as I added that php code the listing area disappeared.

    What could have gone wrong?
    Could you please help me?

    Plugin Author Tijmen Smit

    (@tijmensmit)

    The problem is that as soon as I added that php code the listing area disappeared.

    You mean something breaks in the admin area or the whole front-end of the store locator? Do any errors show up in the browser console ( F12 ) on the store locator page? Trying it in private mode in your browser, with all other plugins and a default WP theme also doesn’t make it work as expected?

    Thread Starter valci1

    (@valci1)

    The browser console says:

    Uncaught ReferenceError: buono is not defined
    at eval (eval at v.template (underscore.min.js?ver=1.8.3:2), <anonymous>:38:2)
    at u (underscore.min.js?ver=1.8.3:2)
    at Object.<anonymous> (wpsl-gmap.min.js?ver=2.2.232:1)
    at Function.each (jquery.js?ver=1.12.4-wp:2)
    at Object.success (wpsl-gmap.min.js?ver=2.2.232:1)
    at i (jquery.js?ver=1.12.4-wp:2)
    at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4-wp:2)
    at x (jquery.js?ver=1.12.4-wp:4)
    at XMLHttpRequest.c (jquery.js?ver=1.12.4-wp:4)

    Thread Starter valci1

    (@valci1)

    Now I’ve tried following this guide https://wpstorelocator.co/document/add-custom-meta-data-to-store-locations/ without doing any change, and it works, but it’s not what I wanted.

    https://spesabollate.it/negozio-piu-vicino-2/

    It has created a link ‘Make an appointment’, but I just want to see there the text I write into the ‘appointment’ field.

    Is it possible?

    Plugin Author Tijmen Smit

    (@tijmensmit)

    That error does suggest a caching issue. Your code itself is fine, it worked for me, but clearly not on your server.

    If you replace line 20 – 22 from this code with the lines below, then it should just show the text.

    $listing_template .= "\t\t\t" . '<% if ( appointment_url ) { %>' . "\r\n";
    $listing_template .= "\t\t\t" . '<p><%= appointment_url %></p>' . "\r\n";
    $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";

    If it doesn’t work, then do remove the type=’url’ from this part of the code.

    • This reply was modified 4 years, 10 months ago by Tijmen Smit.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘New text area not showing’ is closed to new replies.