has_action
Basically, we use the has_action() function to check if any action( callback ) has been registered for a hook.
The WordPress has_action() function expects two parameters when called. The first parameter is $hook_name, and the second parameter $callback is a callback function.
The first parameter, $hook_name, is required. This means you must need to pass the $hook_name with this function. The second parameter $callback is optional.
If the $callback parameter is not passed, it returns a boolean for whether the hook has anything registered. When checking a specific function passing by the second parameter $callback, the priority of that hook is returned or false if the function is not attached.
Let’s see an example:
I developed plugins like Product Catalog Mode For WooCommerce, Woo Parent Category Selector, Remove Add to Cart Button for WooCommerce etc.
In the Remove Add to Cart Button for WooCommerce plugin, I called a callback function with the plugins_loaded action hook to check if WooCommerce is active before running my plugin function.
add_action( 'plugins_loaded', 'ratcw_remove_add_to_cart_button_install', 12 );
function ratcw_remove_add_to_cart_button_install(){
if ( !function_exists( 'WC' ) ) {
add_action( 'admin_notices', 'ratcw_remove_add_to_cart_button_admin_notice' );
} else {
ratcw_run_remove_add_to_cart_button_woocommerce();
}
}
}
So now, if we call the has_action() function like
var_dump(has_action('plugins_loaded','ratcw_remove_add_to_cart_button_install'));
It will return the priority of this callback function.
Here we can see the output is 12, which is the priority of that callback function.
did_action
Retrieves the number of times an action has been fired during the current request. Let’s describe with an example:
If you take a look at the WooCommerce cart template file, you can see an action hook point is created there. Here is the code :
do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );
It calls all callback functions attached to that hook(woocommerce_after_cart_item_name).
So now, if I add a callback function to woocommerce_after_cart_item_name using the add_action() function and add some product to the cart and visit the cart page, there we will see how many times woocommerce_after_cart_item_name is called using did_action('woocommerce_after_cart_item_name'); function.
If you have 3 products on your cart, you will see woocommerce_after_cart_item_name called 3 times.
Please check the screenshot below for more details:

Plugins to Enhance Your WooCommerce Store
Carefully selected tools to help you customize, manage, and optimize your WooCommerce experience.
Woo Parent Category Selector
- Automatically assign parent categories when child categories are selected
- Prevent accidental removal of required parent categories
- Automatically repairs missing parent category assignments during product save
- Bulk repair existing WooCommerce product category structures
- Keeps product category structures organized and consistent
Product Catalog Mode For WooCommerce
- Turn your WooCommerce store into catalog mode instantly
- Hide Add to Cart buttons and product prices conditionally
- Apply rules by user role, country, or scheduled time periods
- Display custom messages and inquiry options for products
- Control visibility settings globally or per product
Remove Add to Cart Button for WooCommerce
- Remove Add to Cart buttons from shop and product pages
- Hide buttons conditionally for selected products or categories
- Replace Add to Cart with custom text or messages
- Control button visibility by user role and product type
- Lightweight settings interface with easy customization
Remove Product Content for WooCommerce
- Hide product title, image, price, rating, and descriptions
- Remove tabs, meta information, SKU, tags, and related products
- Control visibility separately for shop and single product pages
- Customize WooCommerce layouts without coding
- Enable or disable content elements with simple settings
Really Simple XML and HTML Sitemap
- Generate both XML and HTML sitemaps automatically
- Display sitemaps anywhere using ShortCode support
- Include pages, posts, and custom post types
- Exclude selected pages or posts easily
- Supports WPML and Polylang multilingual plugins



