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