更改购物车页面Woocommerce中的“更新购物车”文本

时间:2019-08-01 19:44:55

标签: wordpress woocommerce cart

我正在尝试更改更新购物车按钮的文本。请我在functions.php文件中需要代码,该代码可以在Woocommerce的购物车页面中更改/编辑“更新购物车”文本。 谢谢,

4 个答案:

答案 0 :(得分:0)

查找:>> cart.php

然后查找:

<button type="submit" class="button" name="update_cart" value="<?php esc_attr_e( 
'Update cart', 'woocommerce' ); ?>"><?php esc_html_e( 'Update cart', 'woocommerce' ); 
?></button>

尝试更改第二个“更新购物车”,然后告诉我会发生什么。

答案 1 :(得分:0)

您可以将以下函数复制并粘贴到functions.php中并更改文本。这可行。经过测试

function change_update_cart_text( $translated, $text, $domain ) {
    if( is_cart() && $translated == 'Update cart' ){
        $translated = 'New Text Here';
    }
    return $translated;
}
add_filter( 'gettext', 'change_update_cart_text', 20, 3 );

答案 2 :(得分:0)

获取此文本的另一种方法是将wp-content/plugins/woocommerce/templates/cart/cart.php文件复制到位于wp-content/themes/YOUR_RAD_THEME/woocommerce/cart/cart.php的主题上

您可以在该文件中搜索“更新购物车”。您应该在按钮标签的两个位置找到它。

<button type="submit" class="button" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'woocommerce' ); ?>"><?php esc_html_e( 'Update cart', 'woocommerce' ); ?></button>

将第二个<?php esc_html_e( 'Update cart', 'woocommerce' ); ?>更新为所需的任何文本。幸运的是,您还可以使用该文件来编辑购物车的其他部分。

我会避免使用gettext,因为这是一个全局WordPress过滤器。换句话说,它将在网站上的任意位置替换您的字符串,而不仅仅是该按钮。

答案 3 :(得分:0)

感谢@melvin,我尝试过用此代码编写土耳其语。工作:)

如果您应该粘贴functions.php。不要忘记这里的'SepetiGüncelle'

function change_update_cart_text( $translated, $text, $domain ) {
    if( is_cart() && $translated == 'Update cart' ){
        $translated = 'Sepeti Güncelle';
    }
    return $translated;
}
add_filter( 'gettext', 'change_update_cart_text', 20, 3 );

function change_update_apply_coupon( $translated, $text, $domain ) {
    if( is_cart() && $translated == 'Apply coupon' ){
        $translated = 'Kuponu Uygula';
    }
    return $translated;
}
add_filter( 'gettext', 'change_update_apply_coupon', 20, 3 );

function change_update_coupon_code_text( $translated, $text, $domain ) {
    if( is_cart() && $translated == 'Coupon code' ){
        $translated = 'Kupon Kodu';
    }
    return $translated;
}
add_filter( 'gettext', 'change_update_coupon_code_text', 20, 3 );