WC_Product_Factory::get_product_type PHP Method

get_product_type() public static method

Get the product type for a product.
Since: 2.7.0
public static get_product_type ( integer $product_id ) : string | false
$product_id integer
return string | false
    public static function get_product_type($product_id)
    {
        // Allow the overriding of the lookup in this function. Return the product type here.
        $override = apply_filters('woocommerce_product_type_query', false, $product_id);
        if (!$override) {
            $post_type = get_post_type($product_id);
            if ('product_variation' === $post_type) {
                return 'variation';
            } elseif ('product' === $post_type) {
                $terms = get_the_terms($product_id, 'product_type');
                return !empty($terms) ? sanitize_title(current($terms)->name) : 'simple';
            } else {
                return false;
            }
        } else {
            return $override;
        }
    }