Reputation: 11
I'm trying to add two buttons to Woocommerce / MyAccount / View Order Details (Not in orders list) (ORDER AGAIN | CANCEL) but I only see the 'Order Again' in completed orders but not in other statuses. Thank you!
function cs_add_order_again_to_my_orders_details( $actions, $order ) {
if ( $order->has_status( array( 'completed','pending', 'processing', 'on-hold', 'failed' ) ) ) {
$actions['order-again'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
'name' => __( 'Order Again', 'woocommerce' )
);
// cancel button
$actions['cancel'] = array(
'url' => NO_IDEA,
'name' => NO_IDEA
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_details', 'cs_add_order_again_to_my_orders_details', 50, 2 );
Upvotes: 1
Views: 312
Reputation: 564
By default, only orders with completed
status can be reordered. You can add other statuses with the following hook:
add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'ywp_filter_order_again' );
function ywp_filter_order_again( $statuses ) {
return array( 'completed', 'pending', 'processing', 'on-hold', 'failed' );
}
And for cancel order button:
$actions['cancel'] = array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' ),
);
By default, only orders with pending status can be canceled. You can add other situations with the following hook:
add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'ywp_filter_cancel_order' );
function ywp_filter_cancel_order( $statuses ) {
return array( 'completed', 'pending', 'processing', 'on-hold', 'failed' );
}
Upvotes: 1