在 Woocommerce 的购物车页面上更改购物车总计标题文本
Change cart totals title text on cart page in Woocommerce
我想在 WooCommerce 中更改购物车总计 div 中的文本 "Cart Totals" 或通过操作将其完全删除。
我在 using
的框上方添加了不同的文本
add_action( 'woocommerce_before_cart_totals', 'custom_before_cart_totals' );
function custom_before_cart_totals() {
echo '<h2>Checkout</h2>';
}
但除了编辑 WooCommerce 模板或目标并使用 css 隐藏外,我找不到删除默认措辞 "Cart Totals" 的方法,但我会喜欢可以放在函数文件中的内容更改旧文本或将其完全删除。
如有任何建议,我们将不胜感激。
Default Cart Totals Example
可以使用 WordPress 过滤器挂钩 gettext
。
1) 删除 "Cart totals":
add_filter( 'gettext', 'change_cart_totals_text', 20, 3 );
function change_cart_totals_text( $translated, $text, $domain ) {
if( is_cart() && $translated == 'Cart totals' ){
$translated = '';
}
return $translated;
}
2) 替换(或更改) "Cart totals":
add_filter( 'gettext', 'change_cart_totals_text', 20, 3 );
function change_cart_totals_text( $translated, $text, $domain ) {
if( is_cart() && $translated == 'Cart totals' ){
$translated = __('Your custom text', 'woocommerce');
}
return $translated;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
Or you can remove it from the Woocommerce template cart/cart_totals.php
function change_cart_totals($translated){
$translated = str_ireplace('Cart Totals', 'Cart Total', $translated);
return $translated;
}
add_filter('gettext', 'change_cart_totals' );
将 woocommerce 中的 cart-totals.php
主题复制到您自己的主题中,并替换此行:
<h2><?php esc_html_e( 'Cart totals', 'woocommerce' ); ?></h2>
我想在 WooCommerce 中更改购物车总计 div 中的文本 "Cart Totals" 或通过操作将其完全删除。
我在 using
的框上方添加了不同的文本add_action( 'woocommerce_before_cart_totals', 'custom_before_cart_totals' );
function custom_before_cart_totals() {
echo '<h2>Checkout</h2>';
}
但除了编辑 WooCommerce 模板或目标并使用 css 隐藏外,我找不到删除默认措辞 "Cart Totals" 的方法,但我会喜欢可以放在函数文件中的内容更改旧文本或将其完全删除。
如有任何建议,我们将不胜感激。
Default Cart Totals Example
可以使用 WordPress 过滤器挂钩 gettext
。
1) 删除 "Cart totals":
add_filter( 'gettext', 'change_cart_totals_text', 20, 3 );
function change_cart_totals_text( $translated, $text, $domain ) {
if( is_cart() && $translated == 'Cart totals' ){
$translated = '';
}
return $translated;
}
2) 替换(或更改) "Cart totals":
add_filter( 'gettext', 'change_cart_totals_text', 20, 3 );
function change_cart_totals_text( $translated, $text, $domain ) {
if( is_cart() && $translated == 'Cart totals' ){
$translated = __('Your custom text', 'woocommerce');
}
return $translated;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
Or you can remove it from the Woocommerce template
cart/cart_totals.php
function change_cart_totals($translated){
$translated = str_ireplace('Cart Totals', 'Cart Total', $translated);
return $translated;
}
add_filter('gettext', 'change_cart_totals' );
将 woocommerce 中的 cart-totals.php
主题复制到您自己的主题中,并替换此行:
<h2><?php esc_html_e( 'Cart totals', 'woocommerce' ); ?></h2>