Linear codes with a few weights have applications in data storage systems, secret sharing schemes, and authentication codes. Recently, Ding (IEEE Trans. Inf. Theory 61(6):3265–3275, 2015) proposed a class of ternary linear codes with three weights from a family of cyclic difference sets in $$({\mathbb {F}}_{3^m}^*/{\mathbb {F}}_{3}^*,\times )$$ (F3m∗/F3∗,×) , where $$m=3k$$ m=3k and k is odd. One objective of this paper is to construct ternary linear codes with three weights from cyclic difference sets in $$({\mathbb {F}}_{3^m}^*/{\mathbb {F}}_{3}^*,\times )$$ (F3m∗/F3∗,×) derived from the Helleseth–Gong functions. This construction works for any positive integer $$m=sk$$ m=sk with an odd factor $$s\ge 3$$ s≥3 , and thus leads to three-weight ternary linear codes with more flexible parameters than earlier ones mentioned above. Another objective of this paper is to determine the weight distribution of the proposed linear codes.