Search code examples
hook-woocommerce

On View Order Details page, display payment instructions for orders, where order status = "on hold"


Expected placement for the payment instructions

On the My Account > View Order Page, I want to display the payment instructions for orders that are under "on-hold" status.

How can I add to before or after the Order Detail Table?

A code snippet that I have found (Add custom text under order details on WooCommerce My account view order pages), but does not work

add_action( 'woocommerce_order_details_after_order_table', 'view_order_custom_payment_instruction', 5, 1); // Email notifications
function view_order_custom_payment_instruction( $order ){

    // Only for "on-hold" order statuses and on 'view-order' page
    if( in_array( $order->get_status(), array( 'on-hold' ) ) && is_wc_endpoint_url( 'view-order' ) ){

        // The "Payment instructions" will be displayed with that:
        do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() );

    }
}

Please help


Solution

  • The problem you are facing is that gateways are not loaded everywhere but just on checkout pages. You can change your code to explicitely load gateways and therefore have the action that you are missing

    add_action( 'woocommerce_order_details_after_order_table', 'view_order_custom_payment_instruction', 5, 1); // Email notifications
    function view_order_custom_payment_instruction( $order ){
    
        // Only for "on-hold" order statuses and on 'view-order' page
        if( in_array( $order->get_status(), array( 'on-hold' ) ) && is_wc_endpoint_url( 'view-order' ) ){
            WC()->payment_gateways();
            // The "Payment instructions" will be displayed with that:
            do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() );
    
        }
    }