0
votes

How can I display some custom error message when user clicks "place order" with card payment method selected, is redirected to the bank website, but then hits "cancel" and gets redirected back to WooCommerce thank you page?

The WooCommerce thank you page template code is summarized here (just in case I know how to add custom WooCommerce templates in my child theme):

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

Where does the bank payment cancelling case is located in this code? And how to display a custom message like "you cancelled bank payment, your order has been cancelled"?

1

1 Answers

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

this will help you to achieve your purpose.