try something like this
K[poly_, pairs_] := poly /. ( #-> q+ab & /@ pairs ) /. P[__,__]-> w + cd
Or, closer to your approach:
K[poly_, pairs_] := poly /. P[a_,b_] :> If[MemberQ[pairs,P[a,b]], q+ab, w +cd ]
note you need to expand to get the desired form..
Expand[K[-q P[1, 3] P[4, 6], {P[1, 3], P[2, 7]}]]
(* -ab cd q - cd q^2 - ab q w - q^2 w *)