Need to call function from another php page

I have a php function that I want to call from another php file.  This function creates a button and places a message in Order Notes.  Also, the function isn't the only function in functions.php.

Here is the function
add_action ('woocommerce_before_order_notes', 'member_note', 10); 
function member_note (){
$code = <<< EOT
<button style= "background-color:green; color:white;" onclick="myFunctionMember()">MEMBERSHIP</button>
function myFunctionMember() {
    document.getElementById("order_comments").innerHTML = "I want membership";
echo $code;

Open in new window

This function needs to be at the bottom of this yellow box. which is being created with this code.  

<?php if (($val >= 100) && ($val <= 300)) { ?>
<p style="color: black; font-weight:bold; text-align:center; margin:0 auto; background-color: yellow; padding-top:6px; padding-bottom:6px; font-size:16px; font-family:Verdana, Arial, Helvetica, sans-serif;">
		<span class="heading">You've Qualified For FREE SmartStart Membership!</span><br />
		<br />
  $15 product credit for future use, shipping promotions and much more.</span>
	  <br /><br />
	Click The Green Membership Button To Recieve Your Membership Benefits</p>

<?php include('functions.php');
	$returning_value = member_note();								   
echo $returning_value;
 } ?>

Open in new window

This code is at qv_contest.php

You can see my attempt that resulted in this error:

Fatal error: Cannot redeclare member_note() (previously declared in C:\xampp\apps\wordpress\htdocs\wp-content\themes\flatsome-child\functions.php:25) in C:\xampp\apps\wordpress\htdocs\wp-content\themes\flatsome-child\functions.php on line 33

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Looks like your code is arranged so that the member_note() function is defined twice.

Just place a code guard around your function declaration to only allow one declaration, something like this...

if (! function_exists("member_note")) {
... define your member_note() function here ...

Open in new window

sharingsunshineAuthor Commented:
the error went away but it doesn't display the member button.
Chris StanyonWebDevCommented:
I would strongly recommend that you don't go including the functions.php file in your pages. That's not how the functions file is supposed to be used.

What you should do here is hook into the WordPress action system. Where you need the button, make a call to do_action():

Click The Green Membership Button To Receive Your Membership Benefits</p>
<?php do_action('show_my_button'); ?>

Open in new window

And then in your functions file, just hook into that action:

add_action ('show_my_button', 'member_note', 10);

Open in new window

This is hooking to the same function as before (member_note). Obviously if you're including this block twice on the same page, then you'll be including the JS myFunctionMember() function a second time, so you might need to address that.

FYI - you've spelt receive wrong: Button To Recieve Your Membership

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sharingsunshineAuthor Commented:
Thanks for setting me straight and solving my issue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.