2016-06-09 122 views
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')); 
} 

不知道的最好方式部分覆蓋。有任何想法嗎?

回答

1

自己剛剛遇到同樣的問題。我所做的解決它接近你的解決方案。

而是出隊呢我完全出隊,並上傳excact相同的腳本到我的子主題+註釋掉

`/* 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); 
} ` 
+0

感謝@Freddynøkken。這是有效的,我很樂意接受這個答案。有了警告,我們需要小心未來可能會更改原始文件的WooCommerce更新。 – dpruth

+0

謝謝!是的,我會在未來的更新中關注這一點。 –