【问题标题】:Rename Add to Cart to Buy Now on WooCommerce重命名添加到购物车以在 WooCommerce 上立即购买
【发布时间】:2021-10-13 19:24:24
【问题描述】:

我正在尝试将 WooCommerce 添加到购物车按钮 重命名为 立即购买。但我尝试在functions.php上使用以下代码

// 更改单个产品页面上的添加到购物车文本

add_filter( 'woocommerce_product_single_add_to_cart_text',
 'woocommerce_custom_single_add_to_cart_text' );

function woocommerce_custom_single_add_to_cart_text() {
    return __( 'Add To Bag', 'woocommerce' ); 
}

// 更改产品档案(收藏)页面上的添加到购物车文本

add_filter( 'woocommerce_product_add_to_cart_text',
 'woocommerce_custom_product_add_to_cart_text' );

function woocommerce_custom_product_add_to_cart_text() {
   return __( 'Add To Bag', 'woocommerce' );
}

遗憾的是,代码不会更改文本。对于其他电子商务网站,这对我来说不是问题。该网站使用 Eduma 主题并设计为学习门户。所以,我尝试了所有可能的解决方案,但没有任何效果。即使尝试通过插件更改它也会失败。

如果有人可以帮助我解决此问题,不胜感激。

【问题讨论】:

    标签: wordpress woocommerce wordpress-theming woocommerce-theming


    【解决方案1】:

    您以正确的方式为Woocommerce 站点执行此操作!

    如果您认为 添加到购物车按钮 是针对 Woocommerce 的,只需将 优先级 添加到 add_filter。因为您的主题或插件之一,可能会在您的过滤器之后应用另一个过滤器。您需要确保您的过滤器具有更高的优先级。见例子:

    add_filter( 'woocommerce_product_single_add_to_cart_text',
    'woocommerce_custom_single_add_to_cart_text', 9999);
    
    function woocommerce_custom_single_add_to_cart_text() {
        return __( 'Add To Bag', 'woocommerce' ); 
    }
    

    但我认为该按钮适用于LearnPress,因为使用了Eduma 主题。试试这个:

    add_filter( 'learn-press/purchase-course-button-text', 
    'learnpress_custom_add_to_cart_text', 99);
    
    function learnpress_custom_add_to_cart_text() {
         return 'Buy Now';
    }
    

    【讨论】:

      猜你喜欢
      • 2015-01-15
      • 1970-01-01
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2016-06-20
      • 2015-10-10
      • 2015-08-18
      相关资源
      最近更新 更多