在無法修復 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’;
}
}