I know that add_action is used to call a function at the location of a hook. I used add_action like below and it gives me the output I need (Which is the price of a product in WooCommerce):
add_action( 'woocommerce_before_variations_form', 'woocommerce_single_variation', 10 );
I used the above code inside a custom plugin that i built.
But now I want the price to appear in a different location. I read about do_action and I learned that it is used to make new hooks.
So I made a new hook like below -
do_action('unique_mycustom_hook');
The new hook is kept inside "content-single-product.php" inside Woocommerce template folder.
And then I called my function at my new hook using the code below inside my plugin file.
add_action( 'unique_mycustom_hook', 'woocommerce_single_variation', 10 );
But this time I am NOT getting any output!
Do you have any idea why add_action worked in the pre-existing woocommerce hook but did not work in my new hook made using do_action?
Thanks.
UPDATE - I am adding more information on request.
The purpose of my hook in woocommerce is to have the price of the product appear in a fixed sidebar. So I made a <div>
section inside the file "content-single-product.php"
inside WooCommerce template folder. This is the exact code that I added to the woocommerce template.
<div class="this_sidebar_is_fixed">
<?php
do_action('unique_mycustom_hook');
?>
</div>
Then I am calling the hook using a custom plugin I have.
Still it is not working.