Walmart will pay $5.6 million as part of a settlement in a consumer protection lawsuit that alleged the retailer overcharged its customers.

The Arkansas-based company is accused of overcharging customers and selling products, such as produce, baked goods and other prepared items with less weight than shown on the label, according to the Santa Clara County District Attorney's Office in California.

The civil complaint, filed by four California counties, also alleged that the retailer unlawfully charged customers prices higher than their lowest advertised or posted price.

The Santa Clara's District Attorney's office said Walmart's actions violate California’s False Advertising and Unfair Competition Laws.

"When someone brings an item to the register to be scanned, the price must be right," District Attorney Jeff Rosen said in a statement. "They expect it. California expects it. My office expects it – and we will apply the law to make sure of it."