【问题标题】:WooCommerce: Change the label of the “Return to shop” button in the empty cart pageWooCommerce:更改空白购物车页面中“返回商店”按钮的标签
【发布时间】:2020-10-17 20:11:50
【问题描述】:

我想更改 WooCommerce 中空白购物车页面中“返回商店”按钮中的文字

我在这个sn-p中找到了:

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
});

它仅适用于空购物车页面,但在我删除项目后不在空购物车页面中,我的意思是当出现已删除项目的通知时,按钮仍然是“retun to shop”而不是我的自定义文本..

有什么建议可以让它在各种情况下都能正常工作吗?

【问题讨论】:

    标签: php wordpress woocommerce label shop


    【解决方案1】:

    WooCommerce 4.6 添加了一些新的过滤器和操作:

    其中一个:

    woocommerce_return_to_shop_text - 过滤以更改空白购物车页面中“返回商店”按钮的标签。

    所以你得到

    /**
     * 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 );
    

    【讨论】:

      猜你喜欢
      • 2020-09-08
      • 2017-04-20
      • 1970-01-01
      • 2014-08-09
      • 2018-05-12
      • 2016-10-24
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多