php-stubs / woocommerce-stubs

WooCommerce function and class declaration stubs for static analysis
https://packagist.org/packages/php-stubs/woocommerce-stubs
MIT License
83 stars 10 forks source link

get_variation_price() and get_available_variations() not recognized #11

Closed cristianorevil closed 2 years ago

cristianorevil commented 2 years ago

The functions get_available_variations and get_variation_price used when a product is variable is not recognized: "Undefined method" form intelliphpense

szepeviktor commented 2 years ago

Hello @cristianorevil! I think you refer to WC_Product_Variable::get_available_variations. https://github.com/woocommerce/woocommerce/blob/5.9.0/includes/class-wc-product-variable.php#L289

cristianorevil commented 2 years ago

Yes exact. Is not recognized from intelliphpense

szepeviktor commented 2 years ago
$ grep 'function get_available_variations' woocommerce-stubs.php
        public function get_available_variations($return = 'array')

Do you have the same result on your computer? Latest release: v5.9.0

szepeviktor commented 2 years ago

Maybe your variable is of type WC_Product ...

cristianorevil commented 2 years ago

yes i have the same output on my computer (the functions is present in file woocommerce-stubs.php line 28454)

And yes the viariable is type WC_Product (result of wc_get_product($product_id))

szepeviktor commented 2 years ago

All right! Then this is a design problem.

szepeviktor commented 2 years ago

You could force the type if it is surely WC_Product_Variable.

/** @var \WC_Product_Variable $variable */
$variable = wc_get_product($product_id);