Title: call to undefined function error
Last modified: December 17, 2024

---

# call to undefined function error

 *  Resolved [pprince3145](https://wordpress.org/support/users/pprince3145/)
 * (@pprince3145)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/)
 * I’ve created a universal snippet using a public PHP function declared in an installed,
   working plugin but the snippet won’t save because it can’t find it
    -  This topic was modified 1 year, 5 months ago by [pprince3145](https://wordpress.org/support/users/pprince3145/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18204081)
 * Hi [@pprince3145](https://wordpress.org/support/users/pprince3145/),
 * That may be happening if the function is defined in the plugin later than the
   checks we run before activating the snippet.
 * I recommend adding a check using function_exists before calling that function
   as that should also be helpful if, for example, the other plugin is deactivated
   for any reason.
 * If you share the code of the snippet we’re happy to try to provide a clear example
   of how to add that check.
 *  Thread Starter [pprince3145](https://wordpress.org/support/users/pprince3145/)
 * (@pprince3145)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18204511)
 * Thank for your prompt response
 * I’ve commented where the unrecognised function is called
 *     ```wp-block-code
       <form id="calcForm" class="calcForm-container"> 	<label class="calcformLabel">Bike Type:</label> 		<select id="sku" name="sku" form="calcForm">	<?php// Query Posts.// Query arguments.$query_args = array( 'post_type' => array('product', 'product_variation'), 					'order'                 => 'ASC',					'orderby'               => 'ID',					'posts_per_page' => -1, // Get all products 				   );// Run the query.$query = new WP_Query( $query_args );if ( $query->have_posts() ) {	while ( $query->have_posts() ) {		$query->the_post();		$product = wc_get_product(get_the_ID());		$sku = $product->get_sku();		$name = $product->get_name();		$role_based_price = get_price_of_product($product); // this is the function that cannot be found when the snippet is saved        		if($sku !== "")echo "<option value=\"" . $sku . "|" . $role_based_price . "\">" . $name . "<option>\n";	}} // Reset post data.wp_reset_postdata();?>						</select>		<label class="calcformLabel">Delivery Postcode:</label>		<input type="text" class="calcformInput" id="delivery_postcode" name="delivery_postcode" placeholder="Enter delivery postcode"> 		<button class="calcformlabel" type="button" id="calculate" onClick="calcformSubmit()">Get Quote</button> </form>
       ```
   
 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18205484)
 * Hi [@pprince3145](https://wordpress.org/support/users/pprince3145/),
 * Thank you for sharing your code. I am not familiar with the get_price_of_product
   function, I presume that is from a WooCommerce extension.
 * In any case, you can add a check on that line to prevent the error if the function
   is not found:
 * `$role_based_price = function_exists('get_price_of_product') ? get_price_of_product(
   $product) : '';`
 * If the function exists when the snippet is later executed on the frontend, the
   value returned will be used, otherwise it will be empty.
 * I suggest also double-checking that the function `get_price_of_product` exists.
 *  Thread Starter [pprince3145](https://wordpress.org/support/users/pprince3145/)
 * (@pprince3145)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18206086)
 * sadly that didn’t work
 * all that did was allow me to save the snippet. Not finding the function declared
   in a working plugin is still the issue
 * I’m sure the snippet is executing before the plugin declares the function but
   I have no idea how to resolve that or if it can be
 * thank you
 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18206092)
 * Hi [@pprince3145](https://wordpress.org/support/users/pprince3145/),
 * Can you please share a documentation article or reference of where the function`
   get_price_of_product` is defined?
 * That might help us pinpoint what is causing this issue.
 * If you are calling the snippet as a shortcode, for example, the snippet is executed
   when the shortcode is called so at that point all plugins are definitely loaded.
 *  Thread Starter [pprince3145](https://wordpress.org/support/users/pprince3145/)
 * (@pprince3145)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18206269)
 * I am calling the snippet as a shortcode via Elementor
 * this where the plugin and function are defined
 * ![](https://i0.wp.com/woocommerce-1123782-5085848.cloudwaysapps.com/wp-content/
   uploads/2024/12/Capture.jpg?ssl=1)
 * this is the function I’m trying to call in the snippet
 * ![](https://i0.wp.com/woocommerce-1123782-5085848.cloudwaysapps.com/wp-content/
   uploads/2024/12/rbp-functions.jpg?ssl=1)
 * I hope that helps, thank you
 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18206290)
 * Hi [@pprince3145](https://wordpress.org/support/users/pprince3145/),
 * Thank you for sharing the context. That is a method as part of a class that cannot
   be used as a function in the way you are trying to use it.
 * Functions that can be used the way you are trying to are defined as
 *     ```
       function get_price_of_product() {}
       ```
   
 * In order to use that method, you need to access it in an instance of the class
   that is part of it.
    I can’t see the name of the class in the screenshot if shared,
   but the way that would is something like this:
 *     ```
       $instance = new PriceClass();
   
       $instance->get_price_of_product( $product );
       ```
   
 * The above is just an example, you need to find the instance of that class that
   is likely already loaded and available in a global object or create a new instance
   yourself in order to use that method.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘call to undefined function error’ is closed to new replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/call-to-undefined-function-error-7/#post-18206290)
 * Status: resolved