2017-10-17 64 views
1

爲題說,我想改變從「搜索產品...」搜索字段佔位符「搜索信息......」。我怎樣才能做到這一點?我試圖遵循什麼WooCommerce說對產品searchform.php:如何編輯WooCommerce搜索字段佔位符?

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

要:

class="search-field" placeholder="<?php echo esc_attr__('Search Offers&hellip;', '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> 

我從編輯。我也嘗試在原始WooCommerce product-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超高速緩存?如果沒有,你已經把該文件在錯誤的地方在你的主題文件夾中,覆蓋這樣不工作,並且將覆蓋它 – Deckerz

+0

不,我還沒有啓用緩存,我還沒有安裝像WP超級緩存中的任何插件。我已經把文件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

與測試它。而不是開關($ translated_text)開關($文本),如果沒有,那麼用開關嘗試($域) –

+0

我測試過所有這些,「搜索產品...」是永遠存在!我不知道該做什麼了! – DaniErre

0

的解決辦法是在錯誤的文本域,於我而言,這是 '店鋪島'(主題我使用)而不是'woocommerce'

然後,它不是這樣的:

$translated_text = __('Search Offers&hellip;', 'woocommerce'); 

但是這樣的:

$translated_text = __('Search Offers&hellip;', 'shop-isle');