WooCommerce:取消银行付款时的自定义错误消息

当用户点击“下订单”并选择了卡片付款方式时,如何显示一些自定义错误消息,重定向到银行网站,然后点击“取消”并重定向回WooCommerce谢谢页面?

WooCommerce谢谢你页面模板代码总结在这里(以防万一我知道如何在我的孩子主题中添加自定义WooCommerce模板):

if ( $order ) : ?>

    <?php if ( $order->has_status( 'failed' ) ) : ?>

        <p><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', 'woocommerce' ); ?></p>

    <?php else : ?>

        <p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>

    <?php endif; ?>

    <?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
    <?php do_action( 'woocommerce_thankyou', $order->id ); ?>

<?php else : ?>

    <p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>

<?php endif; ?>

银行付款取消案例在此代码中的位置是什么?如何显示“您取消银行付款,您的订单已被取消”等自定义消息?

回答(1)

2 years ago

function wdm_my_custom_message( $order_id ){
global $woocommerce;
$order=new WC_Order($order_id);
     if ( $order->has_status( 'failed' ) ) {
       $woocommerce->add_error( __( 'you cancelled bank payment, your order has been cancelled.', 'woocommerce' ) );
     }
}

add_action( 'woocommerce_thankyou','wdm_my_custom_message',10,1);

这将帮助您实现目标 .