I am trying to find what exactly do_action and add_action works. I already examine with add_action but for do_action i am trying as new now. This what i tried.
function mainplugin_test() {
$regularprice = 50;
if(class_exists('rs_dynamic')) {
$regularprice = 100;
}
// and doing further
//like i echoing the regular price
echo $regularprice; //It print 100 from this code
}
Now instead of placing few code in main file i am planning to create do_action to avoid code messing issue.
function mainplugin_test() {
$regularprice = 50;
do_action('testinghook');
// and doing further
//like i echoing the regular price
echo $regularprice; //It should print 100 but it print 50
}
so i created another function to point out that hook as something like
function anothertest() {
if(class_exists('rs_dynamic')) {
$regularprice = 100;
}
}
add_action('testinghook','anothertest');
Not sure how to add the lines of code to that hook that above function may work? As per i tried in my testing environment nothing helps. If i understand correct do_action is more like including a file??? If not please advise me.
Thanks.
See Question&Answers more detail:os