Charging is a simple chain: wall outlet, power adapter, charging cable, port, battery. Break any link and the battery stops filling, even though the laptop may still run on wall power.
The weakest links are the cable and the port. Cables bend and fray at the connector, and ports collect lint and dust that block the pins. A port that feels loose often isn't making full contact.
Batteries age too. After a few hundred charge cycles a battery holds less and charges slower, and the system may refuse to charge it at all to protect the hardware.