【问题标题】:How to change Add to basket text on the storefront theme如何更改店面主题上的添加到购物篮文本
【发布时间】:2021-04-27 11:04:20
【问题描述】:

我似乎无法替换单个产品页面上“添加到购物车”按钮中的文本,我正在使用带有 WooCommerce 店面主题的子主题。

这是我尝试过的:

add_filter('woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_add_to_cart_text');

function woocommerce_custom_add_to_cart_text() {
   return __('Add to cart', 'woocommerce');
} 

按钮在 DOM 上的显示方式:

<button type="submit" name="add-to-cart" value="117" class="single_add_to_cart_button button alt">Add to basket</button>

【问题讨论】:

  • 您确定您使用的是storefront 主题吗?因为我在任何地方都找不到主题中的Add to basket 测试。

标签: woocommerce storefront


【解决方案1】:

我确实认为问题与主题有关,因为当我在测试站点上尝试时,您的代码确实有效,尽管我没有将 Storefront 设置为主题。

你可以试试字符串替换:

add_filter( 'gettext', 'change_woocommerce_strings', 999, 3 );

function change_woocommerce_strings( $changed, $text, $domain ) {
$changed = str_ireplace( 'Add to basket', 'Add to cart', $changed );

return $changed;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 2021-12-05
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 2012-06-30
    相关资源
    最近更新 更多