• Resolved Amin Jabari Asl

    (@aminjabari)


    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.

    <?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]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Amin Jabari Asl

    (@aminjabari)

    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.

    Hi @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.