简体   繁体   English

WooCommerce:更改空购物车页面中“返回商店”按钮的标签

[英]WooCommerce: Change the label of the “Return to shop” button in the empty cart page

I would like to change the text in the "return to shop" button in the empty cart page in WooCommerce我想更改 WooCommerce 中空购物车页面中“返回商店”按钮中的文本

I found in this snippet:我在这个片段中发现:

add_action( 'wp_footer', function(){
?>
<script>
jQuery(window).load(function() {
    if (jQuery('a.button.wc-backward'))
        jQuery('a.button.wc-backward').text("My Text");
});
</script>
<?php
});

it's working just for the empty cart page but not in the empty cart page after i remove an item, i mean when appear the notice of the removed item the button still " retun to shop " and not my custom text..它仅适用于空购物车页面,但不适用于我删除商品后的空购物车页面,我的意思是当出现已删除商品的通知时,按钮仍然“ retun to shop ”而不是我的自定义文本。

Any suggestion to make it work in every condition?有什么建议让它在各种情况下都能工作吗?

WooCommerce 4.6 added some new filters and actions: WooCommerce 4.6添加了一些新的过滤器和操作:

One of them:其中之一:

woocommerce_return_to_shop_text - Filter to change the label of the “Return to shop” button in the empty cart page. woocommerce_return_to_shop_text - 过滤以更改空购物车页面中“返回商店”按钮的标签。

So you get所以你得到

/**
 * Filter "Return To Shop" text.
 *
 * @since 4.6.0
 * @param string $default_text Default text.
 */
function filter_woocommerce_return_to_shop_text ( $default_text ) {
    // Add new text
    $default_text = __( 'My new text', 'woocommerce' );
    
    return $default_text;
}
add_filter( 'woocommerce_return_to_shop_text', 'filter_woocommerce_return_to_shop_text', 10, 1 );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从“清空购物车”页面移除或隐藏 WooCommerce“返回商店”按钮? - Removing or hiding WooCommerce "Return to Shop" button from 'empty cart' page? 在结帐时添加一个按钮以清空购物车并重定向到Woocommerce中的商店页面 - Add a button in checkout to empty cart and redirect to shop page in Woocommerce 在Woocommerce商店页面中更改用于简单产品的购物车按钮 - Change add-to-cart button for simple products in Woocommerce shop page 如果购物车为空,购物车页面将重定向到 WooCommerce 中的商店页面? - If cart is empty, the cart page will redirect to shop page in WooCommerce? Woocommerce商店页面(类别页面模板)添加到购物车按钮行为 - Woocommerce shop page (category page template) Add to cart button behavior WooCommerce商店页面:添加到购物车按钮上的数量输入 - WooCommerce Shop page: Quantity input on add to cart button 将数量字段添加到 WooCommerce 商店页面上的 Ajax 添加到购物车按钮 - Add a quantity field to Ajax add to cart button on WooCommerce shop page 更改商店页面中 woocommerce 商店中“添加到购物车”按钮的重定向 - Changing the redirect of the “add to cart” button in woocommerce store in Shop page 在 Woocommerce 3 商店页面上的添加到购物车下添加额外按钮 - Add Extra button under Add to cart on shop page of Woocommerce 3 woocommerce 购物车页面上的空购物车按钮无法正常工作 - Empty cart button on woocommerce cart page does not work properly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM