After a state consumer agency discovered Starbucks Coffee Co. was charging a hidden fee on bags of coffee beans and slapped it with a fine, the coffee giant is dropping the secret surcharge.

Starbucks was adding about $1.50 to the price of bags of coffee beans weighing less than a pound, never posting the addition to the price.

The Massachusetts Office of Consumer Affairs and Business Regulation discovered the practice in late August and fined five Starbucks locations with $1,575 for overcharge violations two weeks ago.

Last week, Starbucks nixed the $1.50 fee - and not just in Massachusetts. Pressure from the state’s consumer agency spurred the company to eliminate the extra charge nationwide.

“It’s a message to the whole marketplace,’’ Barbara Anthony, undersecretary of the Office of Consumer Affairs, said in a phone interview yesterday. “We have to be able to trust that the price we’re paying is the price we should be paying for a particular commodity.’’

When a customer ordered a bag of coffee beans weighing less than 1 pound, Starbucks tacked on about $1.50 to the price without putting up signs about the fee in the store or itemizing the extra charge on receipts.

For example, beans listed at $11.95 per pound ended up costing $7.45 for a half-pound - not $5.98, or 50 percent of the price.

At a Boylston Street Starbucks in Back Bay yesterday, 26-year-old Joseph Hawilo said he was surprised to hear about the extra charge.

“It’s deceptive,’’ said Hawilo, 26, who lives in Chicago but was in Boston on a business trip. “You assume you’re paying less if you’re getting half a pound, and you aren’t.’’

Hawilo’s friend, Erdem Kiciman, 29, estimated that he has bought about eight half-pound bags of freshly ground coffee from Starbucks in the past year and he never looked at the receipt to see whether it matched the price on the display.

“It’s irksome, when you think about it,’’ Kiciman said. “You kind of want to hope that someone has got your back on that.’’

Anthony discovered the discrepancy in late August and the agency checked Starbucks locations in Boston, Brookline, Chestnut Hill, Auburn, Chicopee, Dedham, Framingham, and Holyoke. They also checked Starbucks locations in South Carolina and California. All the stores they checked were adding the $1.50 fee.

Alan Hilowitz, a spokesman for Starbucks, said the company charged for half-pound bags to cover “the additional labor and packaging needed to accommodate those customers’ unique request.’’

It is not illegal to add a fee to the cost of a product, Anthony said, but it is when buyers are not made aware of the extra cost, either with a sign or an announcement by the cashier. That violates the state’s consumer protection act, which requires that customers be informed up front about extra fees that may change the total price of the product they are purchasing.

The Office of Consumer Affairs contacted Starbucks about the violation two months ago.

Two weeks ago, the Division of Standards inspected five stores in Andover, Concord, Reading, Bedford, and Burlington and found that the fee was still in place. The stores were fined $1,575 in total.

The practice of charging a fee for bags of coffee less than a pound had been going on “for years, as far as we know,’’ said Jason Lefferts, a spokesman for the Office of Consumer Affairs.

While the Office of Consumer Affairs was seeking to have the fee abolished in Massachusetts, in keeping with state laws, he said, Starbucks decided to eliminate the surcharge in every store in the United States.

“Obviously,’’ Lefferts said, “we’re pretty psyched about it.’’

Hilowitz said Starbucks regularly reviews prices of items on the menu, and occasionally adjusts those prices.

“We are pleased to be able to now offer our customers alternative sizes of whole bean coffee in all of our US stores, free of any service charge,’’ Hilowitz said.

While Starbucks executives have decided to dispense with the extra fee, that decision has caused confusion, at least in the Boston area. At several Starbucks locations in the past two weeks, reporters who did not identify themselves were told that Starbucks was no longer selling half-pound bags of coffee.

Anthony said Starbucks staff were told not to sell half-pound bags anymore, but that directive has been corrected and the stores will resume selling them soon.

Outside a busy Starbucks on Newbury Street yesterday, Ann Marie Kidd, said she thought the fee was ridiculous.

“That’s their job,’’ she said. “Why do they need to charge you extra for that?’’

Kidd buys coffee beans from Starbucks to share with her husband about once every two weeks; the “extra bold’’ kind is their favorite.

“They don’t charge you a fee when you buy half a pound of bologna at the supermarket,’’ said Frank Kidd, 67, her husband. “With that logic, 5 pounds of coffee should be free.’’

Martine Powers can be reached at mpowers@globe.com.

© Copyright 2011 Globe Newspaper Company.