US retail chain Walmart has apologised after baking a cake containing the flag of the Islamic State of Iraq and the Levant (ISIL) group.

A spokesman for the company told Al Jazeera that it was sorry for the error, which occurred after staff at a local store failed to recognise the image.

"Our talented bakery associates take pride in what they create for our customers...this cake should not have been made and we apologise for the mistake," the spokesman said.

"It’s unfortunate that one customer sought to take advantage of an associate who did not know the flag or its meaning."

The cake was ordered by customer Chuck Netzhammer after his request for a Confederate flag cake was rejected by a local store in Slidell, in the state of Louisiana.

In a video posted on YouTube that has picked up more than 450,000 views, Netzhammer is seen railing against the store for failing to honour his original order, and asking whether the company supports the armed group.

RELATED: US governor calls for Confederate flag to be removed

"That's an ISIL battle flag cake, which anybody can go and buy at Walmart, but you can't buy like a confederate flag toy, like a Dukes of Hazzard car," Netzhammer said, with his camera trained on the cake.

Netzhammer goes on to show the rejection letter given to him by the store, and his originally requested design, which included the words "Heritage, not hate" across the Confederate flag.

He then asks Walmart why the company was "alienating southern Americans".

The Confederate flag, which is associated with the southern states that fought to keep slavery during the American Civil War, has attracted renewed controversy in recent weeks after a deadly attack on a predominantly black church in Charleston, South Carolina.

Dylann Roof, a self-described White supremacist who killed nine people during the course of the attack, had published pictures of himself posing with the flag.

A number of companies, including Walmart, eBay, and Amazon banned the sale of the flag and other merchandise using its image after the shootings, which authorities described as a hate crime.