避免继续到结帐按钮文本刷新为 WooCommerce 购物车页面中的默认文本

Avoid proceed-to-checkout-button text refreshing to default text in WooCommerce cart page

在 WooCommerce 中,在我的店面子主题中,我编辑了 proceed-to-checkout-button.php 中的代码,将措辞从“继续结帐”更改为“结帐”:

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
?>

<a href="<?php echo esc_url( wc_get_checkout_url() ); ?>" class="checkout-button button wc-forward">
    <?php esc_html_e( 'Checkout', 'woocommerce' ); ?>
</a> 

但是当用户在购物车页面中更改产品数量时,按钮文本将恢复为默认的“继续结帐”。

是否有过滤器或在哪里可以编辑此更新后的文本?


编辑 - 问题已解决

The issue was related to a specific cart option in WooCommerce Better Usability pro plugin where the option "Display text while updating cart automatically" requires to be disabled (unselected).

此文件 proceed-to-checkout-button.php 正在从函数 woocommerce_button_proceed_to_checkout() 调用挂接到操作 'woocommerce_proceed_to_checkout' - 您可以在 woocommerce/includes/wc-template-hooks 中找到它。 php

因此,您可以覆盖函数 woocommerce_button_proceed_to_checkout() - 只需将其添加到您的 functions.php

/**
*   Change Proceed To Checkout Text in WooCommerce
*   Add this code in your active theme functions.php file
**/
function woocommerce_button_proceed_to_checkout() {
    
       $new_checkout_url = WC()->cart->get_checkout_url();
       ?>
       <a href="<?php echo $new_checkout_url; ?>" class="checkout-button button alt wc-forward">
       
       <?php _e( 'Go to Secure Checkout', 'woocommerce' ); ?></a>
       
<?php
}

我猜 ajax 按钮的更新可能来自父主题。

不要覆盖 proceed-to-checkout-button.php 文件,而应使用以下内容:

remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
add_action( 'woocommerce_proceed_to_checkout', 'custom_button_proceed_to_checkout', 20 );
function custom_button_proceed_to_checkout() {
    echo '<a href="'.esc_url(wc_get_checkout_url()).'" class="checkout-button button alt wc-forward">' .
    __("Checkout", "woocommerce") . '</a>';
}

代码进入您的活动子主题(或活动主题)的 functions.php 文件。在 Storefront 主题下测试并适用于最后一个 WooCommerce 版本。

Now as you have done a lot of customizations in your templates or may be you are using some plugin in cart page for customization, the problem can remains due to those customizations.