This code allows the customer to reorder their previous orders from the View Orders endpoint on the My Account page. By default, the user must drill-down into the completed order to be able to reorder. This snippet adds a button to allow reordering from a higher level.
/**
* Snippet Name: WooCommerce Order Again From View Orders Endpoint
* Snippet Author: ecommercehints.com
*/
add_filter( 'woocommerce_my_account_my_orders_actions', 'ecommercehints_order_again', 50, 2 );
function ecommercehints_order_again( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) { // Order Again button will only show for completed orders.
$actions['order-again'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
'name' => __( 'Order Again', 'woocommerce' )
);
}
return $actions;
}