【问题标题】:Change text on order button for WooCommerce subscriptions更改 WooCommerce 订阅的订单按钮上的文本
【发布时间】:2018-01-02 10:12:48
【问题描述】:

这里描述的问题正是我需要做的,并且解决方案有效:
Woocommerce: Change text on order button [Updated]

但是,我们接受以捐赠和订阅形式赞助儿童的一次性“订单”。如果购物车中有订阅,结帐按钮会显示“立即注册”。无论购物车里有什么,我都需要它来阅读“立即给予”。

http://www.childhopeonline.org(上述更改尚未生效,目前使用默认的“下订单”,无论购物车中有什么都是一致的)

翻译似乎不起作用。

我也试过了:

function woocommerce_custom_subscription_product_single_add_to_cart_text( $text = '' , $post = '' ) {

    global $product;

    if ( $product->is_type( 'subscription' ) ) {
        $text = get_option( WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text', __( 'Give Now', 'woocommerce-subscriptions' ) );
    } else {
        $text = $product->add_to_cart_text(); // translated "Read More"
    }

    return $text;
}
add_filter('woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_subscription_product_single_add_to_cart_text', 2, 10);

【问题讨论】:

    标签: php wordpress woocommerce checkout woocommerce-subscriptions


    【解决方案1】:

    要更改结帐页面中提交按钮的文本,要使用的正确过滤器挂钩是 woocommerce_order_button_text。这是代码:

    add_filter('woocommerce_order_button_text', 'subscriptions_custom_checkout_submit_button_text' );
    function subscriptions_custom_checkout_submit_button_text( $order_button_text ) {
        if ( WC_Subscriptions_Cart::cart_contains_subscription() ) {
            $order_button_text =  __( 'Give Now', 'woocommerce-subscriptions'  );
        } else {
            // You can change it here for other products types in cart
            # $order_button_text =  __( 'Something here', 'woocommerce-subscriptions'  );
        }
        return $order_button_text;
    }
    

    代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。

    此代码在 woocommerce 3.1+ 上经过测试并且可以正常工作。

    或者您可以在 WooCommerce > 设置 > 订阅中更改它 (标签)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 2016-12-12
      • 2018-05-02
      • 1970-01-01
      • 1970-01-01
      • 2020-12-07
      • 2022-10-05
      相关资源
      最近更新 更多