[NSFW] Comparing two fields (if not empty)

Hi CodePeople!

I have two currency fields (fieldname1 and fieldname2) and a calculated field (fieldname3). I want to compare the entries of the currency fields (only if these are filled):

fieldname3 => IF(fieldname1|r === fieldname2|r),1,0)

This works nice, however, when I want to put it into the following function, empty currency fields are treated as “0” and therefore result in 1:

(function() {
if (fieldname1 !== “” && fieldname2 !== “” && fieldname1 === fieldname2) {
return 1;
} else {
return 0;

What can I do?

Thank you!


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer