• Hi,

    I recently got an error that says the following:

    PHP Fatal error: Uncaught Error: Call to undefined function WPDRMS\ASL\Utils\AdvancedField\Types\wc_get_product() in ../wp-content/plugins/ajax-search-lite/src/server/Utils/AdvancedField/Types/AbstractWooCommerceBase.php:26

    It appears that ASL assumes I’m using woocommerce since I have a custom post type called product. It throw an error when it tries to call undefined function wc_get_product() which is belong to Woocommerce.

    I fixed it by adding this conditional check before calling wc_get_product(). Will you please include this in the next updates? 🙂

    abstract class AbstractWooCommerceBase {
    protected ?WC_Product $product;

    public function __construct( ?stdClass $result ) {
    $this->product = $this->getProduct( $result );
    }

    private function getProduct( ?stdClass $result ): ?WC_Product {
    if ( is_null($result) || !isset($result->post_type) ) {
    return null;
    }
    if ( $result->post_type !== 'product' && $result->post_type !== 'product_variation' ) {
    return null;
    }

    if ( !function_exists( 'wc_get_product' ) ) {
    return null;
    }


    $product = wc_get_product($result->id);
    if ( empty($product) ) {
    return null;
    }

    return $product;
    }

    }

    This fix will allow websites that use ‘product’ as a custom post type to work without needing to install WooCommerce.

Viewing 1 replies (of 1 total)
  • Plugin Support Ernest Marcinko

    (@ernestmarcinko)

    Hi,

    Thank you very much for letting me know. Yes, for sure, I marked this on the issue tracker and make sure to include it in the upcoming version.

    All the best,
    Ernest

Viewing 1 replies (of 1 total)

The topic ‘Undefined function in WPDRMS\ASL\Utils\AdvancedField\Types\wc_get_product()’ is closed to new replies.