Terrible undergraduate transcripts. Everything else is good. Is it still worth applying to a Ph.D program in economics in a top 30 U.S. university? I am an international student who is thinking of applying to a Ph.D program in economics at some top 30 economics departments in the U.S. I have a bachelor's and a master's degree in economics. My GRE, both verbal and quant, puts me well above the 90th percentile. My TOEFL is very high. I have three outstanding recommendations, probably placing me at the top of my master's class and comparing me favorably with former coleagues that were accepted to top universities. My master's disertation will make for a very good writing sample (the paper that grew out of it is serious research, publishable in the best theory journals) and I have two years' work experience at a prestigious job at the public sector. My master's transcripts are almost impeccable, even though I completed a LOT more coursework than what was required to graduate. I have plenty of maths coursework under my belt.

The only "small" wrinkle is: I was the archetype of a wayward student as an undergrad. My undergraduate transcripts are a disaster, as in I flunked 12 of the 70 courses that I enrolled in, simply because I had the terrible habit of abandoning classes when there was something more interesting going on. What I want to know is if this problem destroys my chances of acceptance.
Broadly speaking, your more recent work will matter far more than your past work.  You'll see this as a common theme in the many answers already on Academia SE that relate to this subject.

However, as someone who has been through the economics PhD application process, and knows quite a bit about it, I think you need to temper your "top 30" program cutoff.  To get into top-30 programs you'll often be competing against students who did as well as you in later work, got perfect scores on the GRE quant, AND didn't have problems in past work.  

If your math, at a bare minimum covers differential calculus and real analysis, then given the other things you've said I think you might stand a chance at top-30 programs, especially if your private sector job involved any research with your name on it, even if its just an acknowledgment.  So yes, it's worth applying, but I wouldn't suggest setting your expectations on that range.