[英]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.