【发布时间】:2023-01-28 15:50:23
【问题描述】:
下订单 1 天后,在 Woocommerce 中自动将订单状态从处理中更改为准备中。
下订单后 1 天,在 Woocommerce 中自动将订单状态从处理中更改为准备中。
【问题讨论】:
-
尝试使用 cron Job 和 Hooks。点击此链接link
标签: wordpress woocommerce
下订单 1 天后,在 Woocommerce 中自动将订单状态从处理中更改为准备中。
下订单后 1 天,在 Woocommerce 中自动将订单状态从处理中更改为准备中。
【问题讨论】:
标签: wordpress woocommerce
您可以在 functions.php 中使用此代码
add_action('init', 'wp_orders');
function wp_orders()
{
global $wpdb;
$my_query = "SELECT * FROM wp_wc_order_stats where STATUS='wc-processing'";
$val123 = $wpdb->get_row($my_query, OBJECT);
$result2 = $wpdb->get_results($my_query);
foreach ($result2 as $results2) {
$date1 = $results2->date_created_gmt;
$order_id = $results2->order_id;
$date2=date("Y-m-d h:i:s");
$dteStart = new DateTime($date1);
$dteEnd = new DateTime($date2);
$dteDiff = $dteStart->diff($dteEnd);
$Diff = $dteDiff->format("%d");
$int = (int)$Diff;
if($int>1)
{
$order = new WC_Order($order_id);
if (!empty($order)) {
// change your status to wc-preparing
$order->update_status( 'wc-preparing' );
}
}
}
}
您也可以在 Cpanel 的 cron 作业中设置此功能。
【讨论】:
if(in_array(date('D'),['Sun'])) { return; }在循环之前添加这个条件
add_action('init', 'change_order_status');
function change_order_status() {
global $wpdb;
// Query for orders with a status of "wc-processing"
$my_query = "SELECT * FROM wp_wc_order_stats WHERE STATUS='wc-processing'";
$result = $wpdb->get_results($my_query);
// Iterate through the results
foreach ($result as $order) {
$order_id = $order->order_id;
$order_date = $order->date_created_gmt;
// Get the current date
$current_date = date("Y-m-d h:i:s");
// Calculate the difference in days between the order date and the current date
$dteStart = new DateTime($order_date);
$dteEnd = new DateTime($current_date);
$dteDiff = $dteStart->diff($dteEnd);
$diff_in_days = $dteDiff->format("%d");
// Compare the difference in days to 1
if ($diff_in_days >= 1) {
$order = new WC_Order($order_id);
if (!empty($order)) {
// Change the order status to "wc-accepted"
$order->update_status('wc-accepted');
}
}
}
// Query for orders with a status of "wc-accepted"
$my_query = "SELECT * FROM wp_wc_order_stats WHERE STATUS='wc-accepted'";
$result = $wpdb->get_results($my_query);
// Iterate through the results
foreach ($result as $order) {
$order_id = $order->order_id;
$order_date = $order->date_created_gmt;
// Get the current date
$current_date = date("Y-m-d h:i:s");
// Calculate the difference in days between the order date and the current date
$dteStart = new DateTime($order_date);
$dteEnd = new DateTime($current_date);
$dteDiff = $dteStart->diff($dteEnd);
$diff_in_days = $dteDiff->format("%d");
// Compare the difference in days to 5
if ($diff_in_days >= 5) {
$order = new WC_Order($order_id);
if (!empty($order)) {
// Change the order status to "wc-preparing"
$order->update_status('wc-preparing');
}
}
}
// Query for orders with a status of "wc-preparing"
$my_query = "SELECT * FROM wp_wc_order_stats WHERE STATUS='wc-preparing'";
$result = $wpdb
// Iterate through the results
foreach ($result as $order) {
$order_id = $order->order_id;
$order_date = $order->date_created_gmt;
// Get the current date
$current_date = date("Y-m-d h:i:s");
// Calculate the difference in days between the order date and the current date
$dteStart = new DateTime($order_date);
$dteEnd = new DateTime($current_date);
$dteDiff = $dteStart->diff($dteEnd);
$diff_in_days = $dteDiff->format("%d");
// Compare the difference in days to 6
if ($diff_in_days >= 6) {
$order = new WC_Order($order_id);
if (!empty($order)) {
// Change the order status to "wc-ready-to-ship"
$order->update_status('wc-ready-to-ship');
}
}
}
}
【讨论】: