php 如何在结账时更改 WooCommerce 文本运输
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31017626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change WooCommerce text shipping in checkout
提问by Aaron
I am trying to change a text in the WooCommerce checkout page from Shippingto Deliveryfrom Your OrderSection. I tried to open the core files in FTP and tried to change it manually but I couldn't find the text anywhere. Any help on how to change it?
我想在WooCommerce结帐页面文本改变从运输到配送,从您的订单部分。我尝试在 FTP 中打开核心文件并尝试手动更改它,但在任何地方都找不到文本。有关如何更改它的任何帮助?
回答by Rahul S
Did you tried like this below:
你有没有像下面这样尝试过:
// Add this to your functions.php
add_filter('gettext', 'translate_reply');
add_filter('ngettext', 'translate_reply');
function translate_reply($translated) {
$translated = str_ireplace('Shipping', 'Delivery', $translated);
return $translated;
}
Please see this link too: http://businessbloomer.com/woocommerce-edit-translate-shipping-handling-cart-checkout-page/for more details
请参阅此链接:http: //businessbloomer.com/woocommerce-edit-translate-shipping-handling-cart-checkout-page/了解更多详情
回答by Jose Carlos Ramos Carmenates
I used the solution by @Rahul S but I added the next code to change specific delivery text on cart and checkout.
我使用了@Rahul S 的解决方案,但我添加了下一个代码来更改购物车和结帐上的特定交付文本。
I added this code to the function.php on my theme. It work on cart pageand checkout page
我将此代码添加到我主题的 function.php 中。它适用于购物车页面和结帐页面
You can replace ‘put-here-you-domain-i18n' by you domain, by default it is ‘woocommerce' by I recommend change it.
您可以用您的域替换“put-here-you-domain-i18n”,默认情况下它是“woocommerce”,我建议更改它。
The code to add is:
要添加的代码是:
add_filter( 'woocommerce_shipping_package_name' , 'woocommerce_replace_text_shipping_to_delivery', 10, 3);
/**
*
* Function to replace shipping text to delivery text
*
* @param $package_name
* @param $i
* @param $package
*
* @return string
*/
function woocommerce_replace_text_shipping_to_delivery($package_name, $i, $package){
return sprintf( _nx( 'Delivery', 'Delivery %d', ( $i + 1 ), 'shipping packages', 'put-here-you-domain-i18n' ), ( $i + 1 ) );
}
I hope help you.
我希望能帮到你。
You can see this.
你可以看到这个。
回答by Lucasaid
If you copy the files you need to edit from wp-content/plugins/woocommerce/templates
to wp-content/themes/*your_theme*/woocommerce
. That way you can override the code without touching the plugins code.
如果您将需要编辑的文件从 复制wp-content/plugins/woocommerce/templates
到wp-content/themes/*your_theme*/woocommerce
. 这样你就可以在不触及插件代码的情况下覆盖代码。
You will find the code you need to change will be under wp-content/themes/*your_theme*/woocommerce/checkout
, although if you want to change all instances of the word Shipping you will need to change more of the templates.
您会发现您需要更改的代码位于 下wp-content/themes/*your_theme*/woocommerce/checkout
,但如果您想更改 Shipping 一词的所有实例,您将需要更改更多模板。
List of files that contain Shipping are
包含 Shipping 的文件列表是
woocommerce/cart/cart-shipping.php
woocommerce/cart/cart-shipping.php
woocommerce/cart/cart-totals.php
woocommerce/cart/cart-totals.php
woocommerce/cart/shipping-calculator.php
woocommerce/cart/shipping-calculator.php
woocommerce/checkout/form-billing.php
woocommerce/checkout/form-billing.php
woocommerce/checkout/form-login.php
woocommerce/checkout/form-login.php
woocommerce/emails/email-addresses.php
woocommerce/emails/email-addresses.php
woocommerce/emails/plain/email-addresses.php
woocommerce/emails/plain/email-addresses.php
woocommerce/myaccount/form-edit-address.php
woocommerce/myaccount/form-edit-address.php
woocommerce/myaccount/my-address.php
woocommerce/myaccount/my-address.php
woocommerce/order/order-details.php
woocommerce/order/order-details.php
There is probably more so you'll have to do a search in the other template files.
可能还有更多,因此您必须在其他模板文件中进行搜索。
回答by ZeroGravity
I can see this is an older thread but it had the answer I was looking for. I extended the solution from @Rahul S so the one function could translate multiple strings if desired. It it a revision of a function I use for Event Calendar by ModernTribe. Being in the US I used "Shipping and Handling" in place of "Delivery."
我可以看到这是一个较旧的线程,但它有我正在寻找的答案。我从@Rahul S 扩展了解决方案,因此如果需要,一个函数可以翻译多个字符串。它是我用于 ModernTribe 的 Event Calendar 函数的修订版。在美国,我使用“运输和处理”代替“交付”。
add_filter('gettext', 'zgwd1010_woo_translations', 20, 3);
add_filter('ngettext', 'zgwd1010_woo_translations', 20, 3);
function zgwd1010_woo_translations( $translation, $text, $domain ) {
// Put your custom text here in a key => value pair
$custom_text = array(
'Shipping:' => 'Shipping and Handling:',
);
if( array_key_exists( $translation, $custom_text ) ) {
$translation = $custom_text[$translation];
}
return $translation;
}