Walmart is getting out of the vaping business, but still sells cigarettes. It is working to reduce plastic packaging for the products on its shelves, but continues to use plastic grocery bags in its checkout lines. After a gunman killed 22 people at a Walmart in El Paso this summer, the retailer said it would no longer offer certain types of ammunition, but stopped short of barring customers from carrying their guns into stores.

When navigating the nation’s culture wars, Walmart follows a strategy it has honed for years: Alienate as few customers as possible, and do no harm to its core business. In many cases, it appears to be working. Walmart’s stance on guns, for example, drew a lot of attention but had “no discernible impact” on overall sales, according to a top executive, who spoke on the condition of anonymity to discuss internal matters.

Once viewed in many parts of the country as a union-busting killer of Main Street businesses, Walmart and its chief executive, Doug McMillon, have received plaudits of late for taking stands not just on guns but on issues like carbon emissions and Confederate flags. “When did Walmart grow a conscience?” read a headline in The Boston Globe.

Interviews with more than a dozen Walmart executives, former executives, company advisers and regulators show that the retailer’s approach to public policy issues is more nuanced than a desire to simply do the right thing.