【发布时间】:2018-09-08 18:39:55
【问题描述】:
在 Woocommerce 后端 (admin) 中,我有一个功能,允许商店经理下载两个日期之间的所有订单,其中包含一组特定的所需数据:
function write_to_file($date_initial, $date_final) {
global $attach_download_dir, $attach_download_file;
// Opens/creates file
$myfile = fopen($attach_download_dir . '/' . $attach_download_file, "w") or die("Unable to open file!");
// Populates first line
fwrite($myfile, 'Date; Parent Order ID; Order ID' . PHP_EOL);
// Retrieves orders data
if ( isset($date_initial) && isset($date_final) ) $args = array( 'date_created' => $date_initial . '...' . $date_final );
if ( isset($date_initial) && empty($date_final) ) $args = array( 'date_created' => '>=' . $date_initial );
if ( empty($date_initial) && isset($date_final) ) $args = array( 'date_created' => '<=' . $date_final );
if ( empty($date_initial) && empty($date_final) ) $args = array( );
$orders = wc_get_orders( $args );
// Populates file with orders data
foreach ($orders as $order) {
$order_data = $order->get_data();
fwrite($myfile,
// Date of order creation
$order_data['date_created']->date('d/M/Y') . '; ' .
// Parent Order ID
'#' . ( ( $order->get_type() === 'shop_order' ) ? $order->get_id() : $order->get_parent_id() ) . '; ' .
// Order ID
'#' . $order->get_id()
)
}
}
此功能在按钮单击时触发...
我想从管理订单列表批量选择功能中启用类似的功能。因此,商店经理在管理订单列表中选择的订单(请参阅下面的屏幕截图) 将被发送到类似的自定义脚本,然后下载。
在这种情况下,所选订单将覆盖订单检索中的指定日期(如果有)。
但是,我找不到可以访问的变量来告诉我管理员用户当时选择了哪些订单。
任何帮助将不胜感激......
【问题讨论】:
-
是的,它不见了......
标签: php woocommerce backend bulk orders