Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How To Add Custom Action Tools in WooCommerce

August 8, 2017

2 Min Read
Reading Time: 2 minutes

WooCommerce offers a list of useful default tools (accessed by going to System Status > Tools). However, it is easy to your own custom buttons to this area. This way, you could add custom functionality to your WooCommerce store.

Custom Action Tools in WooCommerce

In this tutorial, I will create a plugin that would add custom action in the WooCommerce tools. In order to add the button, I will start by the hook woocommerce_debug_tools. Next, when  I will create a callback function (called debug_button_action()) that would be triggered when the users click the button. I will place the custom code for the custom action in this function.

Here is the code for the plugin:

<?php
/*
Plugin Name: Cloudways Tools For Custom Button
Description: A simple plugin to add a custom button to WooCommerce tools
Version: 1.0
 */
$GLOBALS['CW_Tools_For_Custom_Button'] = new CW_Tools_For_Custom_Button();
class CW_Tools_For_Custom_Button {

    function __construct() {
        add_filter( 'woocommerce_debug_tools', array( $this,'cw_button_for_debug' ) );
    }
    function cw_button_for_debug( $old ) {
        $new = array(
            'cw_custom_button' => array(
                'name'		=> __( 'Tools Button', '' ),
                'button'	=> __( 'Hit The Button', '' ),
                'desc'		=> __( 'Cloudways Tools For Custom Button', '' ),
                'callback'	=> array( $this, 'cw_button_for_debug_action' ),
            ),
        );
        $tools = array_merge( $old, $new );
        return $tools;
    }
    function cw_button_for_debug_action() {
        echo '<div class="updated"><p>' . __( 'Cloudways custom action triggered', '' ) . '</p></div>';
    }
}

Install & Activate the Plugin

The next step is the activation of the plugin. The first step is the creation of a folder in the Plugin folder. Name the folder “Cloudways Tools” and then create a file inside this folder with the name “CW_tools_for_custom_button.php”.

Next go to the WordPress Admin Panel and you will see a new entry with the name Cloudways Tools For Custom Button.

Custom Tool Plugin

Once you have activated the plugin, go to WooCommerce > System  Status

Tool Button

Once you have hit the button, you will see the following:

Triggered Action

Conclusion

In this short tutorial, I discussed how you could easily create and activate a simple plugin that would create a custom order action to the WooCommerce System Status > Tools. You could easily extend this plugin to add your own custom action to WooCommerce store. Let me know if you need help with the code. Just leave a comment and I will get back to you.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Your WooCommerce Store Needs A Reliable Host

With no compromise on Performance, Security & Support.

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at owais.alam@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!