我已经试了好几个小时了,但无论如何我都不能让这个"基本"的东西工作.
我有一堆支付网关可用,我需要它的名称,包括总订单价值,以包括在"立即付款"按钮文本.
Example:"Order & Pay $49 using Stripe
."
我的代码应该会在网关更改时自动更新 checkout .拜托了,有人吗?
add_filter( 'woocommerce_order_button_text', 'order_button_text_based_on_gateway', 10, 1 );
function order_button_text_based_on_gateway( $cart ) {
// make sure we get the payment gateways
$payment_method = WC()->session->get( 'chosen_payment_method' );
// based on different gateways, display a different button text (place order button)
if ( $payment_method == ' bacs ' ) {
return sprintf( '%s %s', __('Order & Pay', 'woocommerce'),
strip_tags( WC()->cart->get_total() ) . ' using WireTransfer' );
}
elseif ( $payment_method == ' cheque ' ) {
return sprintf( '%s %s', __('Order & Pay', 'woocommerce'),
strip_tags( WC()->cart->get_total() ) . ' with a personal cheque' );
}
elseif ( $payment_method == ' cod ' ) {
return sprintf( '%s %s', __('Order & Pay', 'woocommerce'),
strip_tags( WC()->cart->get_total() ) . ' on delivery' );
}
elseif ( $payment_method == ' etco ' ) {
return sprintf( '%s %s', __('Order & Pay', 'woocommerce'),
strip_tags( WC()->cart->get_total() ) . ' using EtCo' );
}
else ( $payment_method == ' stripe ' ) {
return sprintf( '%s %s', __('Order & Pay', 'woocommerce'),
strip_tags( WC()->cart->get_total() ) . ' using Stripe' );
}
}
The "auto update" checkout script:个
add_action( 'wp_footer', 'reload_checkout_based_on_gateway_change', 999 );
function reload_checkout_based_on_gateway_change() {
if ( is_checkout() && ! is_admin() ) {
// close PHP, get the SCRIPT going
?>
<script>
( function( $ ) {
$( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
$( 'body' ).trigger( 'update_checkout' );
}
);
}
)
( jQuery );
</script>
<?php
}
}