2017-10-17 11 views
1

件名のとおり、検索フィールドのプレースホルダを「検索製品...」から「検索オファー...」に変更したいと考えています。どうやってやるの?私はWooCommerce製品-searchform.phpに言うものをフォローしようとした:WooCommerce検索フィールドのプレースホルダを編集するにはどうすればよいですか?

<?php 
/** 
* The template for displaying product search form 
* 
* This template can be overridden by copying it to yourtheme/woocommerce/product-searchform.php. 
* 
* HOWEVER, on occasion WooCommerce will need to update template files and you 
* (the theme developer) will need to copy the new files to your theme to 
* maintain compatibility. We try to do this as little as possible, but it does 
* happen. When this occurs the version of the template file will be bumped and 
* the readme will list any important changes. 
* 
* @see  https://docs.woocommerce.com/document/template-structure/ 
* @author WooThemes 
* @package WooCommerce/Templates 
* @version 2.5.0 
*/ 

if (! defined('ABSPATH')) { 
    exit; 
} 

?> 
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url(home_url('/')); ?>"> 
    <label class="screen-reader-text" for="woocommerce-product-search-field-<?php echo isset($index) ? absint($index) : 0; ?>"><?php _e('Search for:', 'woocommerce'); ?></label> 
    <input type="search" id="woocommerce-product-search-field-<?php echo isset($index) ? absint($index) : 0; ?>" class="search-field" placeholder="<?php echo esc_attr__('Search products&hellip;', 'woocommerce'); ?>" value="<?php echo get_search_query(); ?>" name="s" /> 
    <input type="submit" value="<?php echo esc_attr_x('Search', 'submit button', 'woocommerce'); ?>" /> 
    <input type="hidden" name="post_type" value="product" /> 
</form> 

私はから編集:

class="search-field" placeholder="<?php echo esc_attr__('Search products&hellip;', 'woocommerce'); ?>" 

へ:

class="search-field" placeholder="<?php echo esc_attr__('Search Offers&hellip;', 'woocommerce'); ?>" 

何も変更されていません。私はまた、元のWooCommerceプロダクトsearchform.phpで同じことをやろうとしました。同じ結果です。

それは便利だ場合、私は要素を検査コード:

<form role="search" method="get" class="woocommerce-product-search" action="https://mywebsite.com/"> 
             <input class="search-field" placeholder="Search Products…" value="" name="s" title="Search for:" type="search"> 
             <input value="Search" type="submit"> 
             <input name="post_type" value="product" type="hidden"> 
            </form> 

CSS:

/**** 
Search form Header 
****/ 
.header-search { 
    float: left; 
    position: relative; 
    width: 25px; 
    height: 25px; 
    text-align: center; 
} 

.header-search-button { 
    color: #cbc7c2; 
    font-size: 14px; 
    line-height: 20px; 
    cursor: pointer; 
} 

.header-search:hover .header-search-button { 
    color: #fff; 
} 

.header-search-input { 
    display: none; 
    position: absolute; 
    top: 100%; 
    right: 0; 
    width: 220px; 
    padding: 5px; 
    background: rgba(26, 26, 26, 0.9); 
} 

.header-search.header-search-open .header-search-input { 
    display: block; 
} 

.header-search.header-search-open .header-search-button { 
    color: #fff; 
} 

.header-search-input input[type=submit] { 
    position: absolute; 
    z-index: 9; 
    top: 5px; 
    right: 5px; 
    width: 28px; 
    height: 33px; 
    border: none; 
    background: none; 
    text-indent: -9999999px; 
} 

.header-search-input input[type="search"] { 
    width: 100%; 
    padding: 10px; 
    padding-right: 28px; 
    border: none; 
    border-radius: 0; 
    font-family: "Roboto Condensed", sans-serif; 
    font-size: 12px; 
    line-height: 12px; 
    letter-spacing: 2px; 
} 

.header-search-input:after { 
    display: inline-block; 
    position: absolute; 
    z-index: 8; 
    top: 5px; 
    right: 5px; 
    width: 20px; 
    width: 33px; 
    color: #999; 
    font-family: "Glyphicons Halflings"; 
    font-size: 12px; 
    font-weight: 400; 
    font-style: normal; 
    -webkit-font-smoothing: antialiased; 
    -moz-osx-font-smoothing: grayscale; 
    line-height: 1; 
    line-height: 33px; 
    content: "\e003"; 
} 

まあ、私は、私が間違っていたトラックの上を歩いていると思うあなたが私を助けることができますか?前もって感謝します。

N.B. "woocommerce/templates/product-searchform.php"にあるプラグイン "product-searchform.php"を編集すると、何も起こらないという衝撃的なことが残っています。ウェブサイト上で起こった

<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url(home_url('/')); ?>"> 
    <label class="screen-reader-text" for="woocommerce-product-search-field-<?php echo isset($index) ? absint($index) : 0; ?>"><?php _e('Search for:', 'woocommerce'); ?></label> 
    <input type="search" id="woocommerce-product-search-field-<?php echo isset($index) ? absint($index) : 0; ?>" class="search-field" placeholder="<?php echo esc_attr__('Search products&hellip;', 'woocommerce'); ?>" value="<?php echo get_search_query(); ?>" name="s" /> 
    <input type="submit" value="<?php echo esc_attr_x('Search', 'submit button', 'woocommerce'); ?>" /> 
    <input type="hidden" name="post_type" value="product" /> 
</form> 

、何の:私はまた、すべてのコードを削除しました!

これはどのように可能ですか? O

+0

を有効にしてしまったことがありますか? WP Super Cacheのようなもの?そうでない場合は、あなたのテーマフォルダの間違った場所にファイルを置いて、その方法が無効になり、それを上書きします。 – Deckerz

+0

いいえ、私はキャッシングを有効にしていないし、WP Super Cacheのようなプラグインをインストールしていません。私はmychildtheme/woocommerceにファイルを置いており、私はwoocommerceディレクトリの外に置こうとしたので、mychildthemeディレクトリでは、どちらの場合も結果はありません。 – DaniErre

答えて

0

このコードを試してみてください:https://www.speakinginbytes.com/2013/10/gettext-filter-wordpress/ これはwordpressのgettextフィルタを使用しており、wordpressのなんでも何でも使用できます。

function my_text_strings($translated_text, $text, $domain) { 
    switch ($translated_text) { 
     case 'Search products&hellip;' : 
      $translated_text = __('Search Offers&hellip;', 'woocommerce'); 
      break; 
    } 
    return $translated_text; 
} 
add_filter('gettext', 'my_text_strings', 20, 3); 

それとも

function my_text_strings($translated_text, $text, $domain) { 
    switch ($text) { 
     case 'Search products&hellip;' : 
      $text = __('Search Offers&hellip;', 'woocommerce'); 
      break; 
    } 
    return $text; 
} 
add_filter('gettext', 'my_text_strings', 20, 3); 

あるいは

add_filter('gettext', 'translate_text'); 
add_filter('ngettext', 'translate_text'); 

function translate_text($translated) { 
$translated = str_ireplace('Search products&hellip;', 'Search Offers&hellip;', $translated); 
return $translated; 
} 
+0

試しました。何もない! :( – DaniErre

+0

)switch($ translated_text)の代わりにswitch($ text)を使用してください。そうでなければswitch($ domain)を試してください –

+0

私はそれらをすべてテストし、 "Search Products ..."もう何をすべきかわからない! – DaniErre

0

ソリューションは、私の場合には、それはお店アイル」だった、という間違ったテキストドメインにあった(私が使用しているテーマ) 'woocommerce'ではなく

次に、このようではありませんでした:

しかし、このような

$translated_text = __('Search Offers&hellip;', 'woocommerce'); 
:あなたはキャッシングが

$translated_text = __('Search Offers&hellip;', 'shop-isle'); 
関連する問題