如何在管理员批量订单操作中跳过具有特定元数据的订单
How to skip orders having specific meta in admin bulk order action
我正在 woocommerce 中创建批量上传货件。我创建了一个订单状态名称 trax-booked
并且在订单管理中我们可以批量 select 订单以在快递平台提交货件。
这是我获取订单数据的代码:
<?php
$count = 0;
$skip = 0;
foreach($object_ids as $orderId) {
$getOrder = new WC_Order($orderId);
$getOrder = $getOrder->get_data();
if($getOrder['status'] == 'trax-booked') {
$skip++;
if(count($object_ids) == $skip) {
wp_redirect(wp_get_referer());
die;
}
continue;
}
$count++;
$itemDesc = '';
$itemQty = 0;
//Get Order Info
$order = new WC_Order($orderId);
$orderData = $order->get_data();
$first_name = $orderData['shipping']['first_name'];
$address_1 = $orderData['shipping']['address_1'];
$phone = $orderData['shipping']['phone'];
$email = $orderData['shipping']['email'];
$city = $orderData['shipping']['city'];
?>
这里我要防止重复预订的订单。所以当订单成功预订时已经添加了这一行
update_post_meta( $order->id, '_dvs_courier_check', '1' );
所以我想添加一个检查,当我 select 多个订单并使用批量编辑功能时, _dvs_courier_check
值 = 1 的订单将跳过并且不会上传到快递平台.请帮助如何做到这一点
您的代码中存在一些错误……要跳过元数据为 _dvs_courier_check
的订单,请尝试以下操作:
<?php
$count = $skip = 0; // Initializing
foreach($object_ids as $order_id ) {
$order = wc_get_order($order_id); // Get WC_Order Object
$order_data = $order->get_data(); // Get default order meta data as an unprotected array
// Skip orders that have '_dvs_courier_check' meta data with value "1"
if( $order->get_meta('_dvs_courier_check') != 1 ) {
if( $order->get_status() === 'trax-booked' ) {
$skip++;
if( count($object_ids) == $count ) {
wp_redirect( wp_get_referer() );
die;
}
continue;
}
$count++;
$itemDesc = '';
$itemQty = 0;
$first_name = $order->get_shipping_first_name();
$address_1 = $order->get_shipping_address_1'];
$phone = $order->get_billing_phone(); // <= billing phone (shipping phone doesn't exist by default)
$email = $order->get_billing_email(); // <= billing email (shipping email doesn't exist by default)
$city = $order->get_shipping_city();
// ... / ...
}
}
?>
应该可以。
我正在 woocommerce 中创建批量上传货件。我创建了一个订单状态名称 trax-booked
并且在订单管理中我们可以批量 select 订单以在快递平台提交货件。
这是我获取订单数据的代码:
<?php
$count = 0;
$skip = 0;
foreach($object_ids as $orderId) {
$getOrder = new WC_Order($orderId);
$getOrder = $getOrder->get_data();
if($getOrder['status'] == 'trax-booked') {
$skip++;
if(count($object_ids) == $skip) {
wp_redirect(wp_get_referer());
die;
}
continue;
}
$count++;
$itemDesc = '';
$itemQty = 0;
//Get Order Info
$order = new WC_Order($orderId);
$orderData = $order->get_data();
$first_name = $orderData['shipping']['first_name'];
$address_1 = $orderData['shipping']['address_1'];
$phone = $orderData['shipping']['phone'];
$email = $orderData['shipping']['email'];
$city = $orderData['shipping']['city'];
?>
这里我要防止重复预订的订单。所以当订单成功预订时已经添加了这一行
update_post_meta( $order->id, '_dvs_courier_check', '1' );
所以我想添加一个检查,当我 select 多个订单并使用批量编辑功能时, _dvs_courier_check
值 = 1 的订单将跳过并且不会上传到快递平台.请帮助如何做到这一点
您的代码中存在一些错误……要跳过元数据为 _dvs_courier_check
的订单,请尝试以下操作:
<?php
$count = $skip = 0; // Initializing
foreach($object_ids as $order_id ) {
$order = wc_get_order($order_id); // Get WC_Order Object
$order_data = $order->get_data(); // Get default order meta data as an unprotected array
// Skip orders that have '_dvs_courier_check' meta data with value "1"
if( $order->get_meta('_dvs_courier_check') != 1 ) {
if( $order->get_status() === 'trax-booked' ) {
$skip++;
if( count($object_ids) == $count ) {
wp_redirect( wp_get_referer() );
die;
}
continue;
}
$count++;
$itemDesc = '';
$itemQty = 0;
$first_name = $order->get_shipping_first_name();
$address_1 = $order->get_shipping_address_1'];
$phone = $order->get_billing_phone(); // <= billing phone (shipping phone doesn't exist by default)
$email = $order->get_billing_email(); // <= billing email (shipping email doesn't exist by default)
$city = $order->get_shipping_city();
// ... / ...
}
}
?>
应该可以。