Reputation: 715
In Woocommerce My account Orders, I am using the following code to Check if customer orders are in "processing" or "shipped" status and if it is the case, display a button to cancel the order:
if ($order_status == 'processing' || $order_status == 'shipped' ){
echo '<a href="click=1" class="woocommerce-button button return">Return Order</a>';
$order->update_status('cancelled');
}
With my code, the order get automatically updated to cancel status when the status was "processing" or "shipped" and I can't get the button to work. I want to make that happen on button click to trigger the update_status.
I want to make it appear in view order page like this
Right now the cancel order isn't functional
How can I do? without using Javascript?
Any help is welcome.
Upvotes: 2
Views: 2811
Reputation: 254378
The following code will enable the Woocommerce "cancel" cation button in My account orders list, also for processing
or shipped
order statuses (default Woocommerce statuses are here pending
and failed
):
add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'custom_valid_order_statuses_for_cancel', 10, 1 );
function custom_valid_order_statuses_for_cancel( $statuses ){
// Set HERE the order statuses where you want the cancel button to appear
return array_merge( $statuses, array('processing', 'shipped'));
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Upvotes: 3