Tuesday, January 24, 2023
HomeWordPress DevelopmentUtilizing woocommerce capabilities inside a customized shortcode

Utilizing woocommerce capabilities inside a customized shortcode


I’m creating a customized plugin.

The principle goal of this plugin is to create a customized shortcode.

Inside callback operate of this plugin, I take advantage of a few of woocommerce capabilities.
However I get “name to undefined operate (any woocommerce operate)” error.

For sake of simplicity, I created a really primary plugin to explain this drawback.

<?php  

add_shortcode('custom_shortcode','custom_shortcode_callback');

operate custom_shortcode_callback(){

    $order_id = 81201; 
    $order = wc_get_product($order_id);
    echo 'something';

}

?>

I get this error:
Uncaught Error: Name to undefined operate wc_get_product().

In some solutions concerning this drawback, the answer was to hook ‘woocommerce_init’ or ‘woocommerce_loaded’ actions. However I need to echo some end in web page and simply hooking to those actions, doesn’t present my shortcode’s intention.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments