public function idBySlug(string $slug, bool $no_cache = false): int
    {
        static $product_ids;

        if (!($slug = (string) $slug)) {
            return 0; // Not possible.
        } elseif (isset($product_ids[$slug])) {
            return $product_ids[$slug];
        } elseif ((string) (int) $slug === $slug) {
            return $product_ids[$slug] = (int) $slug;
        }
        $WpDb = $this->s::wpDb(); // DB instance.

        $sql = /* Get the product ID for this slug. */ '
            SELECT `ID` FROM `'.esc_sql($WpDb->posts).'`
                WHERE
                    `post_type` IN(\'product\', \'product_variation\')
                    AND `post_name` = %s
            LIMIT 1';
        $sql = $WpDb->prepare($sql, $slug); // Prepare.

        if (($product_id = (int) $WpDb->get_var($sql))) {
            return $product_ids[$slug] = $product_id;
        }
        return $product_ids[$slug] = 0; // Not possible.
    }
public function idBySlug(string $slug, bool $no_cache = false): int
    {
        static $product_ids;

        if (!($slug = (string) $slug)) {
            return 0; // Not possible.
        } elseif (isset($product_ids[$slug])) {
            return $product_ids[$slug];
        } elseif ((string) (int) $slug === $slug) {
            return $product_ids[$slug] = (int) $slug;
        }
        $WpDb = $this->s::wpDb(); // DB instance.

        $sql = /* Get the product ID for this slug. */ '
            SELECT `ID` FROM `'.esc_sql($WpDb->posts).'`
                WHERE
                    `post_type` IN(\'product\', \'product_variation\')
                    AND `post_name` = %s
            LIMIT 1';
        $sql = $WpDb->prepare($sql, $slug); // Prepare.

        if (($product_id = (int) $WpDb->get_var($sql))) {
            return $product_ids[$slug] = $product_id;
        }
        return $product_ids[$slug] = 0; // Not possible.
    }
public function idBySlug ( string $ slug , bool $ no_cache = false ) : int { static $ product_ids ; if ( ! ( $ slug = ( string ) $ slug ) ) { return 0 ; // Not possible. } elseif ( isset ( $ product_ids [ $ slug ] ) ) { return $ product_ids [ $ slug ] ; } elseif ( ( string ) ( int ) $ slug === $ slug ) { return $ product_ids [ $ slug ] = ( int ) $ slug ; } $ WpDb = $ this -> s :: wpDb ( ) ; // DB instance. $ sql = /* Get the product ID for this slug. */ '
            SELECT `ID` FROM `' . esc_sql ( $ WpDb -> posts ) . '`
                WHERE
                    `post_type` IN(\'product\', \'product_variation\')
                    AND `post_name` = %s
            LIMIT 1' ; $ sql = $ WpDb -> prepare ( $ sql , $ slug ) ; // Prepare. if ( ( $ product_id = ( int ) $ WpDb -> get_var ( $ sql ) ) ) { return $ product_ids [ $ slug ] = $ product_id ; } return $ product_ids [ $ slug ] = 0 ; // Not possible. }
Product ID by slug.

@since 160727 WC product utils.

@param string $slug     Product slug.
@param bool   $no_cache Bypass cache check?

@return int Product ID.
Product ID by slug .