• Resolved Group Of Oceninfo

    (@princebhalani143)


    Hi Team,

    I would like to disable the option for customers to cancel orders through the /my-account/ page. I want to restrict this functionality to improve our order management process.

    I am looking for a solution to disable the cancel order option specifically in the customer’s account area.

    Thanks,
    Group of Oceninfo

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey there ??

    Thanks for reaching out!

    It looks like you want to remove the “cancel” button in the “My Account” dashboard, to prevent customers from directly cancelling an order, correct?

    There is no built-in option within WooCommerce core that allows for this button to be removed, however it’s possible to hide the button from being displayed by using custom CSS.

    Can you try adding the following CSS to?Appearance?→ Customize → Additional CSS?and see if this does the trick:

    /*  Hide cancel button in My Account dashboard  */
    a.woocommerce-button.button.cancel {
        display: none !important
    }

    Here are the results before and after:

    BEFORE CSS:

    AFTER CSS:

    If you’d like to learn more about CSS, I highly recommend using the free tutorials at w3schools. Here, you can find the basics of selectors (how to target the right element on the page), and properties (how to change the element on the page).

    Hope this helps!

    Thread Starter Group Of Oceninfo

    (@princebhalani143)

    @beautyofcode Thank you for providing CSS solution, Is there any hook based solution where we can remove the button instead of hiding it.

    Hey @princebhalani143,

    Is there any hook based solution where we can remove the button instead of hiding it.

    Although help with custom code is outside?our scope of support, you can try the following code snippet and see if this does the trick:

    add_filter('woocommerce_my_account_my_orders_actions', 'remove_myaccount_orders_cancel_button', 10, 2);
    function remove_myaccount_orders_cancel_button( $actions, $order ){
        unset($actions['cancel']);
    
        return $actions;
    }

    Direct code link: https://gist.github.com/stoltzrx/e47b6d69caa8e9833e7f0ee5436ea110

    I have tested this code on my test site and it is working as expected.

    You need to add the code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin.

    Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme.

    Cheers!

    Hey there ??,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – feel free to?create a new topic?if you need any further help. ??

    Cheers!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to Prevent Customers To Cancel WooCommerce Orders’ is closed to new replies.