Thank you to anyone who can help. I'm trying to use PHP to get a delivery date that is X days from any given current day. This is to use with the Google Survey Opt-in code and WooCommerce in WordPress.
Referencing this thread: WooCommerce fill-in fields for Google Survey Opt-In Code
Google wants dynamic values, explained here: https://support.google.com/merchants/answer/7106244?hl=en&ref_topic=7105160#example
I have most of the code ready to go, but this dynamic date has been hard to figure out.
I think the simplest solution is to just add a number of days to the day of a product order, which can happen on any given day.
My question is: how do I get PHP to calculate that in this context?
My understanding is that there is DateTime and there is strtotime, but DateTime is the more recent and 'right' way to do this?
This is what I've got so far, but I'm not sure it's right:
//Google Survey code
function wh_CustomReadOrder($order_id) {
//getting order object
$order = wc_get_order($order_id);
$email = $order->billing_email;
?>
<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
<script>
window.renderOptIn = function () {
window.gapi.load('surveyoptin', function () {
window.gapi.surveyoptin.render(
{
"merchant_id": [merchant id],
"order_id": "<?php echo $order_id; ?>",
"email": "<?php echo $email; ?>",
"delivery_country": "CA",
"estimated_delivery_date": "<?php
$inOneWeek = new \DateTime("+7 day");
echo $date->format("Y-m-d");
?>"
}
);
});
};
</script>
<?php
}
add_action('woocommerce_thankyou', 'wh_CustomReadOrder');