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

时间:2015-06-27 12:03:37

标签: 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 个答案:

答案 0 :(得分:0)

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);

这将帮助您实现目标。