标签: 改变订单状态
- 该话题包含 2 个回复,2 人参与,最后由
lmn40227 更新于 4 年、 11 月前 。
-
作者帖子
-
在无法修复 Woocommerce 偶然性的发生 一个订单里 产品出现 2 次, 但客户支付了一次钱. 在这个前提下, 决定在客户下订单时, 判断如果客户的订单里的 item_name 发生重复的状态下, 就将订单的状态改成 on-hold.
下面的代码 是我加在 function 页面的, 测试的错误提示: SyntaxError: Unexpected token < in JSON at position 18, 求大神们指点下 下面代码哪里有问题, 万分感谢
add_filter( ‘woocommerce_cod_process_payment_order_status’, ‘prefix_filter_wc_complete_order_status’, 10, 3 );
add_filter( ‘woocommerce_payment_complete_order_status’, ‘prefix_filter_wc_complete_order_status’, 10, 3 );function prefix_filter_wc_complete_order_status( $status, $order_id, $order ) {
if( ! $order_id ) return;
$order = wc_get_order( $order_id );$all_products_id = array();
foreach ($order->get_items() as $item_key => $item ){
$item_name = $item->get_name();
$all_products_id[] = $item_name;
}$o_num = count($all_products_id);
if($o_num == 1){
return ‘processing’;
}else{$standard = 0;
for($i=1;$i<$o_num;$i++){
if($all_products_id[0] == $all_products_id[i]){
$standard++;
}
}if($standard > 0){
return ‘on-hold’;
}else{
return ‘processing’;
}}
没明白这么操作的意思,如果是客户下单重复,而且你又只收到一次钱,那么只有两种可能,一种是未付款放弃购买,一种是已付款但交易中断支付平台数据回调没成功。
一个订单里 产品出现 2 次, 但客户支付了一次钱
直接限制一个订单里只允许加入一个单独购买产品就行了。
好的 谢谢
-
作者帖子
- 哎呀,回复话题必需登录。