Home > Back-end >  wordpress woocommerce how to add payment button inside order
wordpress woocommerce how to add payment button inside order

Time:08-06

There is a list of orders in /my-account/orders/ in woocommerce personal account. Opposite each order is its status and if the order is not paid, then the "pay" button appears. But when you go to the order itself, there is no "pay" button. How to add a "pay" button exactly inside the order itself in the user's personal account? Perhaps there are hooks for these purposes?

CodePudding user response:

Try the following simplified code version, that will display a pay order button for pending orders:

add_action( 'woocommerce_view_order', 'order_pay_button' );

function order_pay_button( $order_id ){
    // Get an instance of the `WC_Order` Object
    $order = wc_get_order( $order_id );

    if ( $order->get_status() == "pending" ) {
        printf(
            '<a  href="%s/order-pay/%s/?pay_for_order=true&key=%s">%s</a>',
            wc_get_checkout_url(), $order_id, $order->get_order_key(), __("Pay for this order", "woocommerce")
        );
    }
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.

  • Related