Website Building » WooCommerce » How Do I Add a Cancel Order Button in WooCommerce?

How Do I Add a Cancel Order Button in WooCommerce?

Last updated on January 23, 2023 @ 7:16 am

If you’re using WooCommerce to run your online store, you may be wondering how to add a “cancel order” button to your site. This can be a useful feature if you need to cancel an order for any reason. Here’s how to do it.

First, log in to your WordPress site and go to the WooCommerce plugin settings. Next, click on the “Orders” tab and then click on the “Cancel Order” button.

You’ll see a pop-up window asking you to confirm the cancellation. Once you confirm, the order will be canceled and a notice will be displayed on the screen.

You can also add a “cancel order” button to your site by editing your theme’s template files. To do this, go to the “Appearance” tab in your WordPress dashboard and click on “Editor.” Find the template file that contains the code for your “order history” page and add the following code:

PRO TIP: Adding a cancel order button in WooCommerce is not recommended as it can create confusion for customers and lead to accidental cancellations. If you do add a cancel order button, be sure to clearly label it and explain its purpose to avoid any confusion.

<?php if ( $order->status != 'completed' ) : ?>
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'cancel_order', $order->id ), 'woocommerce-cancel_order' ) ); ?>" class="button cancel-order"><?php _e( 'Cancel Order', 'woocommerce' ); ?></a>
<?php endif; ?>

Save your changes and then go to your “order history” page to test it out. You should now see a “cancel order” button next to each order that isn’t completed.

Adding a “cancel order” button to your WooCommerce store can be a useful way to manage orders that need to be canceled for any reason. By following the steps above, you can easily add this button to your site.

Madison Geldart

Madison Geldart

Cloud infrastructure engineer and tech mess solver.