WooCommerce Namespace / Stubs for VS Code with Intelephense

I’m developing a theme with Sage 9 for a woocommerce-Shop. It’s my first Sage-Project, so I’m struggling with some stuff here. When using WooCommerce-Specific Functions in my IDE (VS Code with Intelephense) all these Woocommerce-specific functions and classes and so on are shown as undefined:

Undefined function 'App\wc_get_template_html'. intelephense(1010)

This for example comes from my setup.php where I want to run the wc_get_template_html-function.

I already installed the Woocommerce Integration from sage (https://github.com/roots/sage-woocommerce) and was hoping that this provides me a namespace I could use inside my controllers and other files. But it doesn’t (Or does it?).

I also installed the WooCommerce Stubs from https://github.com/php-stubs/woocommerce-stubs and added it to the intelephense.environment.includePaths like so:

"intelephense.environment.includePaths": [
    "${workspaceFolder}/vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php"
]

But still: Showing undefined function.
Can anybody please point me into the correct direction to get my IDE recognise WooCommerce-Functions?

1 Like

Is WooCommerce plugin activated?

Can you try adding a backslash in front of the WC function call? Sth like this:

\wc_get_template_html($args)

that way will force to bypass the App namespace…

Thanks for your response.
I don’t have the WooCommerce-Plugin in my theme-Folder. In my IDE I only work inside of the theme-Folder not in the whole Wordpress-Tree. This basically means woocommerce is installed and acitvated on my Dev-Instance, but not inside my theme. That’s why I thought I might need something like the stubs.

\wc_get_template_html($args)

does not work either. I tried that already but same Error-message

This topic was automatically closed after 42 days. New replies are no longer allowed.