Procter & Gamble's bet on raising prices amid higher commodity and transportation costs is paying off for the consumer products giant.

Shares surged more than 4.7 percent in premarket trading Wednesday after P&G's fiscal second-quarter earnings and sales report outpaced Wall Street estimates, prompting the company to raise its organic sales forecast.

Its beauty products, health care and fabric and home care businesses all contributed to the gains. The company said about 1 percent of its organic sales growth in the quarter came from higher pricing.

Here's what the company reported compared with what Wall Street was expecting, based on a survey of analysts by Refinitiv:

Earnings per share: $1.25, adjusted vs. $1.21 estimated

Revenue: $17.44 billion vs. $17.15 billion estimated

"We delivered strong organic sales in the second quarter, building on our first quarter momentum, which enables us to increase our outlook for the year," David Taylor, chairman, president and CEO, said in a statement. "Our focus on superiority, productivity and improving P&G's organization and culture is delivering improved results despite a challenging competitive and macroeconomic environment."

P&G reported fiscal second-quarter net income of $3.19 billion, or $1.22 per share, up from $2.5 billion, or 93 cents per share a year earlier.

Excluding restructuring costs and other items, the company earned $1.25 per share, higher than $1.21 per share expected by analysts surveyed by Refinitiv

Net sales rose slightly to $17.44 billion, beating expectations of $17.15 billion. On an organic basis, which excludes the impact of foreign exchange and acquisitions and divestitures, sales were up 4 percent.

Organic sales at its beauty care business rose 8 percent year over year during the latest period, driven by strong demand for its super-premium SK-II brand and its Olay skin care products as well as higher prices.

At its health care division, which includes its Crest toothpaste brand, organic sales rose 5 percent. The company said product innovation was helping its performance in oral care and personal health care.

Shoppers are trading up to more premium products at its fabric and home care business, the company said. Organic sales at this division rose 6 percent during the quarter.

However, P&G's grooming business, which includes its Gillette brand, continues to struggle, and organic sales fell 3 percent. Its shave care business continued to show volume declines during the quarter.

P&G raised the high-end of its organic sales growth forecast by 1 percent. The company now expects organic sales to rise in the range of 2 to 4 percent for fiscal 2019. Total sales are expected to be within the range of down 1 percent to up 1 percent.

Foreign exchange and higher commodity and transportation costs are expected to be a $1.4 billion headwind in fiscal 2019.

The company backed its prior earnings forecast, which calls for core earnings per shares to rise 3 to 8 percent from fiscal 2018 core earnings of $4.22 per share.

P&G said it plans to buy back as much as $5 billion in stock this fiscal year.

The company announced in November it is reorganizing its operational structure, a move activist investor Nelson Peltz lobbied for before he joined the board in March. As part of P&G's new business structure, the company will now have six sector business units organized by industry. Each business will have a unit CEO responsible for running all major decisions, like marketing, costs and supply chain.

P&G, which has a market value of $225.3 billion, has seen its shares drop nearly 2 percent over the past year.

Tune into CNBC Thursday at 10 a.m. ET to see Sara Eisen's interview with Procter & Gamble CEO David Taylor at Davos.