PHP 7.4.33
Preview: test.php Size: 5.78 KB
/var/www/antons.wpress.dk/httpdocs/test.php
<?php
include('wp-config.php');

add_action('woocommerce_process_shop_order_meta', 'hck_test_delivery_date', 10, 3);

function hck_test_delivery_date($process_shop_order, $int1, $int2 = '')
{
    $order = wc_update_order(array('order_id' => $process_shop_order));
    $testing_del_date = get_field('change_delivery_date', $process_shop_order);
    $address = $order->get_address();
    if ($testing_del_date) {
        $address['myfield13'] = $testing_del_date;
    }
    if (!empty($address)) {
        $order->set_address($address, 'shipping');
        $order->set_address($address);
    }
    $order = wc_update_order(array('order_id' => $process_shop_order));
}

$saved_orders = get_posts(
    array(
        'numberposts' => -1,
        'post_type' => wc_get_order_types(),
        'post_status' => 'wc-pending',
        'p' => 3807
    )
);
foreach ($saved_orders as $saved_order) {
    try {
        $order = new WC_Order($saved_order->ID);
        $edit_link = get_post_meta($order->id, 'order_update_link', true);
        $ule_notified_admin = get_post_meta($saved_order->ID, 'update_link_expiry_notified_admin', true);
        if (!$edit_link)
            return;

        $myfield13 = explode(' ', $order->billing_myfield13);
        $delivery_date = $myfield13[0];
        $expiry_date = date("d/m/Y", strtotime(str_replace("/", "-", $delivery_date) . ' -5 days'));
        $expiry_timestamp = date("dmY", strtotime(str_replace("/", "-", $delivery_date) . ' -5 days'));

        print_r($expiry_date);

//        Edit link expiry notification(7 days before) 7 days before delivery, 2 days before expiry
        $ule_notified = get_post_meta($saved_order->ID, 'update_link_expiry_5days_notified', true);
        if (!$ule_notified) {
            echo "7 days" . '<br>';
            $delivery_timestamp = date("dmY", strtotime(str_replace("/", "-", $delivery_date) . ' -7 days'));
            $current_date = date("dmY", strtotime("now"));
            echo '<br>' . $current_date;
            echo '<br>' . $delivery_timestamp;
            /*if ($current_date == $delivery_timestamp) {
                $mailer = WC()->mailer();
                // Create new WC_Email instance
                $mails = $mailer->get_emails();
                $mail = $mails['WC_Order_Edit_Expiry_Email'];
                $mail->trigger($saved_order->ID, $expiry_date, "2 dage til frist om redigering", 7);
                $note = __("Edit link expiry notification (7 days before delivery/2days before link expiry) is sent to customer");
                $order->add_order_note($note);
                //update_post_meta($saved_order->ID, 'update_link_expiry_5days_notified', 1);
            }*/
        }
//        Edit link expiry notification (5 days before)
        $ule5b_notified = get_post_meta($saved_order->ID, 'update_link_expiry_notified', true);
        if (!$ule5b_notified) {

            echo '<br>' . "5 days" . '<br>';
//                $current_date_5days = date('dmY', strtotime('+5 days')); //+10 days before delivery, 5 days before link expiry
//                if ($current_date_5days == $expiry_timestamp) {
            $delivery_timestamp = date("dmY", strtotime(str_replace("/", "-", $delivery_date) . ' -5 days'));
            $current_date = date("dmY", strtotime("now"));
            echo '<br>' . $current_date;
            echo '<br>' . $delivery_timestamp;
            /*if ($current_date == $delivery_timestamp) {
                $mailer = WC()->mailer();
                // Create new WC_Email instance
                $mails = $mailer->get_emails();
                $mail = $mails['WC_Order_Edit_Expiry_Email'];
                $mail->trigger($saved_order->ID, $expiry_date, "Sidste frist for redigering", 5);
                $note = __("Edit link expiry notification (5 days before delivery/on link expiry day) is sent to customer");
                $order->add_order_note($note);
                update_post_meta($saved_order->ID, 'update_link_expiry_notified', 1);
            }*/
        }

//        Payment notification (1 day before) - if not already paid
        $pbd_notified = get_post_meta($saved_order->ID, 'payment_before_delivery_notified', true);
        if (!$pbd_notified) {

            echo '<br>' . "1 days" . '<br>';
            $payment_daybefore = date("dmY", strtotime(str_replace("/", "-", $delivery_date) . ' -1 days'));
            $current_date_1day = date("dmY", strtotime("now"));
            echo '<br>' . $current_date;
            echo '<br>' . $delivery_timestamp;

            /*if ($payment_daybefore == $current_date_1day) {
                $mailer = WC()->mailer();
                // Create new WC_Email instance
                $mails = $mailer->get_emails();
                $mail = $mails['WC_Order_Edit_Expiry_Email'];
                $mail->trigger($saved_order->ID, $delivery_date, "Husk at betale din ordre", 1);
                $note = __("Payment notification (1 day before delivery) is sent to customer");
                $order->add_order_note($note);
                //update_post_meta($saved_order->ID, 'payment_before_delivery_notified', 1);
            }*/
        }
//      /*/*/*  Admin notification
        /*$current_admin_date = date('dmY', strtotime('-1 days'));
        if ($current_admin_date == $expiry_timestamp && !$ule_notified_admin) { // day after link expired
            $mailer = WC()->mailer();
            // Create new WC_Email instance
            //$mails = $mailer->get_emails();
            //$mail = $mails['WC_Order_Edit_Expiry_Email_Admin'];
            $mail->trigger($saved_order->ID, $expiry_date);*/
        //update_post_meta($saved_order->ID, 'update_link_expiry_notified_admin', 1);
        //}*/*/*/
    } catch (Exception $e) {
        echo '<br>error<br>';

        print_r($e);
    }
}

Directory Contents

Dirs: 5 × Files: 27
Name Size Perms Modified Actions
- drwxrwxr-x 2026-05-13 23:59:38
Edit Download
images DIR
- drwxrwxr-x 2016-11-12 12:38:44
Edit Download
wp-admin DIR
- drwxrwxr-x 2023-10-03 12:02:15
Edit Download
- drwxrwxr-x 2024-02-02 05:44:32
Edit Download
- drwxrwxr-x 2024-01-25 08:19:44
Edit Download
666 B lrw-rw-r-- 2024-02-01 11:42:50
Edit Download
191.64 MB lrw-r--r-- 2024-02-16 05:10:16
Edit Download
833.86 MB lrw-rw-r-- 2023-10-17 11:53:42
Edit Download
166 B lrw-rw-r-- 2019-12-12 11:38:04
Edit Download
53 B lrw-rw-r-- 2016-11-18 05:54:56
Edit Download
53 B lrw-rw-r-- 2016-10-05 06:08:58
Edit Download
53 B lrw-rw-r-- 2019-06-13 09:10:27
Edit Download
405 B lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
22.61 KB lrw-rw-r-- 2017-06-26 11:20:43
Edit Download
19.45 KB lrw-rw-r-- 2024-04-10 11:30:52
Edit Download
20.43 MB lrw-r--r-- 2024-02-16 07:05:27
Edit Download
7.23 KB lrw-rw-r-- 2026-03-11 09:44:57
Edit Download
5.78 KB lrw-rw-r-- 2019-03-26 09:35:55
Edit Download
7.04 KB lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
351 B lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
2.27 KB lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
2.94 KB lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
3.79 KB lrw-rw-r-- 2024-01-24 08:59:57
Edit Download
5.51 KB lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
2.44 KB lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
3.83 KB lrw-rw-r-- 2023-10-03 12:02:16
Edit Download
49.73 KB lrw-rw-r-- 2024-01-31 13:16:20
Edit Download
8.33 KB lrw-rw-r-- 2024-01-25 08:19:44
Edit Download
25.79 KB lrw-rw-r-- 2024-01-25 08:19:44
Edit Download
33.58 KB lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
4.77 KB lrw-rw-r-- 2023-10-03 12:02:15
Edit Download
3.08 KB lrw-rw-r-- 2024-01-25 08:19:44
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).