我想在商店信息下方的信息窗口(电子邮件下方)添加自定义文本。
我遵照以下指示:
https://wpstorelocator.co/document/add-custom-meta-data-to-store-locations/
因此,我在worpress主题的function.php文件中添加了以下内容:
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' => __( 'Tel', 'wpsl' )
),
'fax' => array(
'label' => __( 'Fax', 'wpsl' )
),
'email' => array(
'label' => __( 'Email', 'wpsl' )
),
'url' => array(
'label' => __( 'Url', 'wpsl' )
),
'my_textinput' => array(
'label' => __( 'Textinput', 'wpsl' )
)
);
return $meta_fields;
}
function custom_frontend_meta_fields( $store_fields ) {
$store_fields['wpsl_my_textinput'] = array(
'name' => 'my_textinput',
'type' => 'text'
);
return $store_fields;
}
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";
$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";
$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 ) %>(1)</span>' . "\r\n";
$info_window_template .= "\t\t" . '<% } %>' . "\r\n";
$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 %>(2)</span>' . "\r\n";
$info_window_template .= "\t\t" . '<% } %>' . "\r\n";
$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 ) %>(3)</span>' . "\r\n";
$info_window_template .= "\t\t" . '<% } %>' . "\r\n";
$info_window_template .= "\t\t" . '<% if ( my_textinput ) { %>' . "\r\n";
$info_window_template .= "\t\t" . '<p><%= my_textinput %></p>' . "\r\n";
$info_window_template .= "\t\t" . '<% } %>' . "\r\n";
$info_window_template .= "\t\t" . '<%= createInfoWindowActions( id ) %>' . "\r\n";
$info_window_template .= "\t" . '</div>' . "\r\n";
return $info_window_template;
}
当我添加以下代码(几乎是结尾)时,信息窗口不会显示:
$info_window_template .= "\t\t" . '<% if ( my_textinput ) { %>' . "\r\n";
$info_window_template .= "\t\t" . '<p><%= my_textinput %></p>' . "\r\n";
$info_window_template .= "\t\t" . '<% } %>' . "\r\n";
我在DevTool控制台上得到以下错误:
Uncaught ReferenceError: my_textinput is not defined
at eval (eval at m.template (underscore.min.js?ver=1.8.3:5), <anonymous>:52:2)
at c (underscore.min.js?ver=1.8.3:5)
at H (wpsl-gmap.min.js?ver=2.2.15:1)
at _.ze.<anonymous> (wpsl-gmap.min.js?ver=2.2.15:1)
at Object.trigger ...
如何确保数据包含在JSON输出中?