skip to Main Content

I’m trying to put the Order Again button on thankyou page but it doesn’t work, what did I do wrong?

My code on thankyou page

<?php echo esc_url( $order_again_url ); ?>

In my function.php I’m using

add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'add_order_again_status', 10, 1);

function add_order_again_status($array){
    $array = array_merge($array, array('on-hold', 'processing', 'pending-payment', 'cancelled', 'refunded'));
    return $array;
}

2

Answers


  1. Reorder only allow with order status -> completed.
    If you want to reorder on thankyou page so first you should allow status for reorder with on-hold, pending, processing etc..
    like this:

    add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'allowed_order_again_status', 10, 1);
    function allowed_order_again_status($array){
        $array = array_merge($array, array('on-hold','pending', 'processing', 'completed'));
        return $array;
    }
    

    Then add reorder button by using woocommerce_thankyou hooks like this:

    add_filter( 'woocommerce_thankyou', 're_order_woocommerce_thankyou', 4 );
    function re_order_woocommerce_thankyou($order_id) {
        $order = wc_get_order($order_id);
        if ( $order->has_status( 'completed' ) || $order->has_status( 'processing' ) || $order->has_status( 'pending' ) || $order->has_status( 'on-hold' ) ) {
            $actions['order-again'] = array(
                'url'  => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
                'name' => __( 'Order Again', 'woocommerce' )
            ); 
            ?>
            <a class="btn btn-primary" href="<?php echo $actions['order-again']['url'];?>" ><?php echo $actions['order-again']['name'];?> </a>
            <?php 
            return $order_id;
        }
    }
    

    Note: Reorder button will be visible on buttom of page but If you want Reorder button on any position on thankyou page then you shoult override thankyou page just copy from woocommerce plugin and past inside you active theme -> woocommerce -> thankyou.php and add reorder button accordingly

    Login or Signup to reply.
  2. Reorder button/link for my account page -> order tab like this:

    add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'allowed_order_again_status', 10, 1);
    function allowed_order_again_status($array){
        $array = array_merge($array, array('on-hold','pending', 'processing', 'completed'));
        return $array;
    }
    
    add_filter( 'woocommerce_my_account_my_orders_actions', 'woo_order_again_from_myaccount', 50, 2 );
    function woo_order_again_from_myaccount( $actions, $order ) {
        if ( $order->has_status( 'completed' ) || $order->has_status( 'processing' ) || $order->has_status( 'pending' ) || $order->has_status( 'on-hold' ) ) {
            $actions['order-again'] = array(
                'url'  => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
                'name' => __( 'Order Again', 'woocommerce' )
            );
        }
    
        return $actions;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search