Woocommerce:更改订单按钮上的文字 [英] Woocommerce: Change text on order button

查看:32
本文介绍了Woocommerce:更改订单按钮上的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个非营利性网站上使用 WooCommerce,想将下订单"按钮文本更改为下单".该按钮在 WooCommerce 的 payment.php 文件中定义:

I am using WooCommerce for a nonprofit website and want to change the "Place Order" button text to say "Place Donation". The button is defined in WooCommerce's payment.php file:

<?php echo apply_filters( 'woocommerce_order_button_html', 
    '<input type="submit" class="button alt" name="woocommerce_checkout_place_order" 
    id="place_order" value="' . esc_attr( $order_button_text ) . 
    '" data-value="' . esc_attr( $order_button_text ) . '" />' ); ?>

我在子主题的functions.php文件中添加了以下内容:

I added the following to my functions.php file in the child theme:

function custom_order_button_text($order_button_text){
    $order_button_text = 'Place Donation';

    return $order_button_text;
}
add_filter('woocommerce_order_button_text', 'custom_order_button_text');

它暂时似乎可以工作,但在页面完成加载之前变回下订单".输出 HTML 最终为:

It momentarily seems to work, but changes back to 'Place Order' before the page finishes loading. The output HTML ends up as:

<input type="submit" class="button alt" name="woocommerce_checkout_place_order" 
id="place_order" value="Place order" data-value="Place Donation">

*更新:我关闭了 javascript,发现按钮然后显示捐赠".然后我在 woocommerce/assets/js/frontend/checkout.js 中找到了一个脚本作为payment_method_selected的一部分

*Update: I turned off javascript and found that the button then said "Place Donation." I then found a script in woocommerce/assets/js/frontend/checkout.js as part of payment_method_selected

if ( $( this ).data( 'order_button_text' ) ) {
    $( '#place_order' ).val( $( this ).data( 'order_button_text' ) );
} else {
    $( '#place_order' ).val( $( '#place_order' ).data( 'value' ) );
}

不确定覆盖它的最佳方法.有什么想法吗?

Not sure the best way to override this. Any ideas?

推荐答案

我自己也遇到了同样的问题.我为解决它所做的与您的解决方案很接近.

Just came across the same issue myself. What I did to solve it is close to your solution.

我没有将其完全出列,而是将其完全相同的脚本上传到我的子主题 + 注释掉

Instead of dequeueing it completely I dequeued it and uploaded the excact same script to my child theme + commented out

 `/* if ( $( this ).data( 'order_button_text' ) ) {
    $( '#place_order' ).val( $( this ).data( 'order_button_text' ) );
} else {
    $( '#place_order' ).val( $( '#place_order' ).data( 'value' ) );
}*/ `

PHP:

`add_action('wp_enqueue_scripts', 'override_woo_frontend_scripts');
function override_woo_frontend_scripts() {
    wp_deregister_script('wc-checkout');
    wp_enqueue_script('wc-checkout', get_template_directory_uri() . '/../storefront-child-theme-master/woocommerce/checkout.js', array('jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n'), null, true);
}    `

这篇关于Woocommerce:更改订单按钮上的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆