Title: Using woocommerce functions inside a custom shortcode
Last modified: January 24, 2023

---

# Using woocommerce functions inside a custom shortcode

 *  Resolved [Amin Jabari Asl](https://wordpress.org/support/users/aminjabari/)
 * (@aminjabari)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/using-woocommerce-functions-inside-a-custom-shortcode/)
 * I am developing a custom plugin.
 * The main purpose of this plugin is to create a custom shortcode.
 * Inside callback function of this plugin, I use some of woocommerce functions.
   But I get “call to undefined function (any woocommerce function)” error.
 * For sake of simplicity, I created a very basic plugin to describe this problem.
 *     ```wp-block-code
       <?php  
   
       add_shortcode('custom_shortcode','custom_shortcode_callback');
   
       function custom_shortcode_callback(){
   
           $order_id = 81201; 
           $order = wc_get_product($order_id);
           echo 'anything';
   
       }
   
       ?>
       ```
   
 * I get this error: Uncaught Error: Call to undefined function wc_get_product().
 * In some answers regarding this problem, the solution was to hook ‘woocommerce_init’
   or ‘woocommerce_loaded’ actions. But I want to echo some result in page and just
   hooking to these actions, does not provide my shortcode’s intention.
   I use this
   shortcode inside a WordPress page editor like this:
 * [custom_shortcode]
    -  This topic was modified 3 years, 4 months ago by [Amin Jabari Asl](https://wordpress.org/support/users/aminjabari/).

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

 *  Thread Starter [Amin Jabari Asl](https://wordpress.org/support/users/aminjabari/)
 * (@aminjabari)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/using-woocommerce-functions-inside-a-custom-shortcode/#post-16405096)
 * After further inspection, I found out that some setting in Assets CleanUp plugin
   were the culprit.
 * After deactivating this plugin, problem resolves. sorry for posting this question.
 *  [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * (@xue28)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/using-woocommerce-functions-inside-a-custom-shortcode/#post-16409940)
 * Hi [@aminjabari](https://wordpress.org/support/users/aminjabari/)
 * Thanks for reaching out!
 * I’m glad you were able to find a solution to your inquiry here and thanks for
   sharing it with the community too! 🙂
 * Cheers!

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

The topic ‘Using woocommerce functions inside a custom shortcode’ is closed to new
replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 2 replies
 * 2 participants
 * Last reply from: [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/using-woocommerce-functions-inside-a-custom-shortcode/#post-16409940)
 * Status: resolved