Date field conditionals | WordPress.org

[ad_1]

Hello @garteth

I’ll try to describe the process with a hypothetical example.

Assuming you are referring to the prices per day and fieldname1 and fieldname2 are date fields for check-in and check-out, respectively.

You can calculate the final price day to day by implementing the equation entered in the calculated field as follows:

(function(){
var price_month = {1:20, 2:20, 3:20, 4:40, 5:40, 6:40, 7:60, 8:60, 9:60, 10:80, 11:80, 12:90},
check_in = MIN(fieldname1, fieldname2),
check_out = MAX(fieldname1, fieldname2),
price = 0;

while(check_in <= check_out){
price += price_month[MONTH(check_in)];
check_in++;
}

return price;
})()

And that’s all.

Best regards.

 

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