"processing" 个订单的送货地址相同时的管理员通知
Admin notification when shipping address is the same on "processing" orders
我 own/operate 一家 WooCommerce 商店,我正在寻找一种方法来设置商店通知,当多个订单来自同一客户并运送到同一地址时。
我很幸运能够拥有大量的回头客。他们会在比方说星期一从我的商店订购并支付他们商品的运费然后在星期二订购(在我能够发出第一个订单之前),所以我尝试包括第二个产品进入第一个订单 "SAVE" 发货。但是我只有注意客户的收货地址并捆绑商品才能节省运费。
我希望我的网站在这方面的效率更高一些,并检查 "OPEN" 或 "PROCESSING" 具有匹配送货地址的订单,并在我打开其中一个订单时弹出警报有问题的订单...
这样的事情可能吗?
我搜索了又搜索又搜索,什么都没有...我不完全确定从哪里开始...
functions.php 文件中的自定义脚本是否可行?
有没有插件可以帮助做到这一点?
非常感谢任何帮助。
谢谢。
For WooCommerce version 2.5.x and 2.6.x
For WOOCOMMERCE VERSION 3.0+ see
这完全有可能在 woocommerce_admin_order_data_after_order_details
操作挂钩中使用自定义挂钩函数,其中 您必须在其中定义数组 订单状态 用于您的“未结订单”。
这是经过测试的功能代码:
add_action( 'woocommerce_admin_order_data_after_order_details', 'same_shipping_open_order', 10, 1 );
function same_shipping_open_order( $order ){
// Define HERE, in the array, your "OPEN" orders statuses
$open_order_statuses = array('wc-pending','wc-processing','wc-on-hold');
// Initialising variables
$matching = false;
// Get the shipping 'address_1' & 'postcode' fields for the CURRENT ORDER
$order_ship_address1 = $order->shipping_address_1;
$order_ship_postcode = $order->shipping_postcode;
// Getting customer orders, with an open status
$open_orders = wc_get_orders( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $order->get_user_id(),
'post_type' => 'shop_order',
'post_status' => $open_order_statuses,
'exclude' => array($order->id),
) );
// Other "Open" orders for this customer
if( count($open_orders) != 0 ){
// Iterating through each orders
foreach($open_orders as $open_order){
if( $order_ship_address1 == $open_order->shipping_address_1 && $order_ship_postcode == $open_order->shipping_postcode ){
$matching = true; // set condition to true
$open_order_id = $open_order->id;
// Other orders edit url
$order_edit_url = home_url( "/wp-admin/post.php?post=$open_order_id&action=edit/" );
// Storing orders edit url + ID
$results_arr[] = "<a href='$order_edit_url'>#$open_order_id</a>";
}
}
}
// If there is matching "Open" orders shipping addresss with this order
if ( $matching ) {
## 0. Converting the array in a string for output
$output_html = implode(', ', $results_arr);
## 1. Displaying an alert message on the order
echo '<br clear="all"><p style="margin-top:12px !important;"><strong style="color:red;">'. __("Same Shipping on Open Orders IDs: ").'</strong><br>'.$output_html.'</p>';
## 2. Javascript Alert message
?>
<script>
(function($){
alert('SAME SHIPPING ON OPEN ORDERS!');
})(jQuery);
</script>
<?php
}
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
You will get an alert message when opening/editing the order and also a text with the related "Open orders Ids and edit links. See the screenshot below:
Version code for WooCommerce 3+
add_action( 'woocommerce_admin_order_data_after_order_details', 'same_shipping_open_order', 10, 1 );
function same_shipping_open_order( $order ){
// Define HERE, in the array, your "OPEN" orders statuses
$open_order_statuses = array('wc-pending','wc-processing','wc-on-hold');
// Initialising variables
$matching = false;
// Get Order data (WC 3+ compatibility)
$order_data = $order->get_data();
// Get the shipping 'address_1' & 'postcode' fields for the CURRENT ORDER
$order_ship_address1 = $order_data['shipping']['address_1']; # (WC 3+ compatibility)
$order_ship_postcode = $order_data['shipping']['postcode']; # (WC 3+ compatibility)
// Getting customer orders, with an open status
$open_orders = wc_get_orders( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $order->get_user_id(),
'post_type' => 'shop_order',
'post_status' => $open_order_statuses,
'exclude' => array($order_data['id']), # (WC 3+ compatibility)
) );
// Other "Open" orders for this customer
if( count($open_orders) != 0 ){
// Iterating through each orders
foreach($open_orders as $open_order){
// Get "open" Order data (WC 3+ compatibility)
$open_order_data = $open_order->get_data();
// Orders Id
$open_order_id = $open_order_data['id'];
if( $order_ship_address1 == $open_order_data['shipping']['address_1'] && $order_ship_postcode == $open_order_data['shipping']['postcode'] ){
// set condition to true (There is at once 1 matched order)
$matching = true;
// Other orders edit url
$order_edit_url = home_url( "/wp-admin/post.php?post=$open_order_id&action=edit/" );
// Storing orders edit url + ID
$results_arr[] = "<a href='$order_edit_url'>#$open_order_id</a>";
}
}
}
// If there is matching "Open" orders shipping addresss with this order
if ( $matching ) {
## 0. Converting the array in a string for output
$output_html = implode(', ', $results_arr);
## 1. Displaying an alert message on the order
echo '<br clear="all"><p style="margin-top:12px !important;"><strong style="color:red;">'. __("Same Shipping on Open Orders IDs: ").'</strong><br>'.$output_html.'</p>';
## 2. Javascript Alert message
?>
<script>
(function($){
alert('SAME SHIPPING ON OPEN ORDERS!');
})(jQuery);
</script>
<?php
}
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
此代码已经过测试,在 WooCommerce 3+
上的工作方式相同
查看此相关的更新答案:如何获取订单详细信息
在 WooCommerce 3.0+
我 own/operate 一家 WooCommerce 商店,我正在寻找一种方法来设置商店通知,当多个订单来自同一客户并运送到同一地址时。
我很幸运能够拥有大量的回头客。他们会在比方说星期一从我的商店订购并支付他们商品的运费然后在星期二订购(在我能够发出第一个订单之前),所以我尝试包括第二个产品进入第一个订单 "SAVE" 发货。但是我只有注意客户的收货地址并捆绑商品才能节省运费。
我希望我的网站在这方面的效率更高一些,并检查 "OPEN" 或 "PROCESSING" 具有匹配送货地址的订单,并在我打开其中一个订单时弹出警报有问题的订单...
这样的事情可能吗?
我搜索了又搜索又搜索,什么都没有...我不完全确定从哪里开始...
functions.php 文件中的自定义脚本是否可行?
有没有插件可以帮助做到这一点?
非常感谢任何帮助。
谢谢。
For WooCommerce version 2.5.x and 2.6.x
For WOOCOMMERCE VERSION 3.0+ see
这完全有可能在 woocommerce_admin_order_data_after_order_details
操作挂钩中使用自定义挂钩函数,其中 您必须在其中定义数组 订单状态 用于您的“未结订单”。
这是经过测试的功能代码:
add_action( 'woocommerce_admin_order_data_after_order_details', 'same_shipping_open_order', 10, 1 );
function same_shipping_open_order( $order ){
// Define HERE, in the array, your "OPEN" orders statuses
$open_order_statuses = array('wc-pending','wc-processing','wc-on-hold');
// Initialising variables
$matching = false;
// Get the shipping 'address_1' & 'postcode' fields for the CURRENT ORDER
$order_ship_address1 = $order->shipping_address_1;
$order_ship_postcode = $order->shipping_postcode;
// Getting customer orders, with an open status
$open_orders = wc_get_orders( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $order->get_user_id(),
'post_type' => 'shop_order',
'post_status' => $open_order_statuses,
'exclude' => array($order->id),
) );
// Other "Open" orders for this customer
if( count($open_orders) != 0 ){
// Iterating through each orders
foreach($open_orders as $open_order){
if( $order_ship_address1 == $open_order->shipping_address_1 && $order_ship_postcode == $open_order->shipping_postcode ){
$matching = true; // set condition to true
$open_order_id = $open_order->id;
// Other orders edit url
$order_edit_url = home_url( "/wp-admin/post.php?post=$open_order_id&action=edit/" );
// Storing orders edit url + ID
$results_arr[] = "<a href='$order_edit_url'>#$open_order_id</a>";
}
}
}
// If there is matching "Open" orders shipping addresss with this order
if ( $matching ) {
## 0. Converting the array in a string for output
$output_html = implode(', ', $results_arr);
## 1. Displaying an alert message on the order
echo '<br clear="all"><p style="margin-top:12px !important;"><strong style="color:red;">'. __("Same Shipping on Open Orders IDs: ").'</strong><br>'.$output_html.'</p>';
## 2. Javascript Alert message
?>
<script>
(function($){
alert('SAME SHIPPING ON OPEN ORDERS!');
})(jQuery);
</script>
<?php
}
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
You will get an alert message when opening/editing the order and also a text with the related "Open orders Ids and edit links. See the screenshot below:
Version code for WooCommerce 3+
add_action( 'woocommerce_admin_order_data_after_order_details', 'same_shipping_open_order', 10, 1 );
function same_shipping_open_order( $order ){
// Define HERE, in the array, your "OPEN" orders statuses
$open_order_statuses = array('wc-pending','wc-processing','wc-on-hold');
// Initialising variables
$matching = false;
// Get Order data (WC 3+ compatibility)
$order_data = $order->get_data();
// Get the shipping 'address_1' & 'postcode' fields for the CURRENT ORDER
$order_ship_address1 = $order_data['shipping']['address_1']; # (WC 3+ compatibility)
$order_ship_postcode = $order_data['shipping']['postcode']; # (WC 3+ compatibility)
// Getting customer orders, with an open status
$open_orders = wc_get_orders( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $order->get_user_id(),
'post_type' => 'shop_order',
'post_status' => $open_order_statuses,
'exclude' => array($order_data['id']), # (WC 3+ compatibility)
) );
// Other "Open" orders for this customer
if( count($open_orders) != 0 ){
// Iterating through each orders
foreach($open_orders as $open_order){
// Get "open" Order data (WC 3+ compatibility)
$open_order_data = $open_order->get_data();
// Orders Id
$open_order_id = $open_order_data['id'];
if( $order_ship_address1 == $open_order_data['shipping']['address_1'] && $order_ship_postcode == $open_order_data['shipping']['postcode'] ){
// set condition to true (There is at once 1 matched order)
$matching = true;
// Other orders edit url
$order_edit_url = home_url( "/wp-admin/post.php?post=$open_order_id&action=edit/" );
// Storing orders edit url + ID
$results_arr[] = "<a href='$order_edit_url'>#$open_order_id</a>";
}
}
}
// If there is matching "Open" orders shipping addresss with this order
if ( $matching ) {
## 0. Converting the array in a string for output
$output_html = implode(', ', $results_arr);
## 1. Displaying an alert message on the order
echo '<br clear="all"><p style="margin-top:12px !important;"><strong style="color:red;">'. __("Same Shipping on Open Orders IDs: ").'</strong><br>'.$output_html.'</p>';
## 2. Javascript Alert message
?>
<script>
(function($){
alert('SAME SHIPPING ON OPEN ORDERS!');
})(jQuery);
</script>
<?php
}
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
此代码已经过测试,在 WooCommerce 3+
上的工作方式相同查看此相关的更新答案:如何获取订单详细信息 在 WooCommerce 3.0+