Changing sale price programmatically, but it’s not shown on front-end

I figured I’d post the answer here as well in case someone else is going to look for the answer.

Why the sale price wasn’t changing completely was because I wasn’t changing al the required fields.

Woocommerce has 3 different fields for keeping the price for every product.
There is the regular price field, sale price and a third one. When I set the sale price, I also had to change the regular price field to be the same as the sale price. Otherwise, Woocommerce did not recognise it.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)