0
我正在爲非營利網站使用WooCommerce,並希望將「Place Order」按鈕文本更改爲「Place Donation」。該按鈕在WooCommerce的payment.php文件中定義:Woocommerce:更改訂單按鈕上的文本[已更新]
<?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文件:
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結束爲:
<input type="submit" class="button alt" name="woocommerce_checkout_place_order"
id="place_order" value="Place order" data-value="Place Donation">
*更新:「將捐贈」我關掉javascript和發現按鈕,然後說:然後我發現了一個腳本woocommerce /資產/ JS /前端/ checkout.js作爲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'));
}
不知道的最好方式部分覆蓋。有任何想法嗎?
感謝@Freddynøkken。這是有效的,我很樂意接受這個答案。有了警告,我們需要小心未來可能會更改原始文件的WooCommerce更新。 – dpruth
謝謝!是的,我會在未來的更新中關注這一點。 –