Avatar of sharingsunshine
sharingsunshineFlag for United States of America

asked on 

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>
<script>
function myFunctionMember() {
    document.getElementById("order_comments").innerHTML = "I want membership";
}
</script>
EOT;
echo $code;
}

Open in new window


This function needs to be at the bottom of this yellow box.  https://gyazo.com/fad06970c1cec8be092987e46331a7c3 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

PHPWordPressLinux Distributions

Avatar of undefined
Last Comment
sharingsunshine
Avatar of David Favor
David Favor
Flag of United States of America image

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

Avatar of sharingsunshine

ASKER

the error went away but it doesn't display the member button.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of sharingsunshine

ASKER

Thanks for setting me straight and solving my issue.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo