我遇到了一個問題,我認為它可能與站點/服務器相關,而不是與代碼相關,因為該站點的資料庫很大,并且此代碼之前運行良好,我從未更改過它。但我正在做的是從 woocommerce 商店獲取所有與它相關的“附屬公司”的訂單。我用這段代碼做到這一點:
$order = wc_get_orders( array(
'status'=> 'wc-completed',
'meta_key' => '_coupon_codes_CCAFF_Aff_Affiliate_ID',
)
);
然后我有一個用戶表單,用戶可以在其中輸入開始日期和結束日期以及其他一些資訊以進行查詢。(如果需要,我可以在此處添加代碼,但盡量保持簡短)
然后,我運行一個 foreach 回圈,盡管我在其中回顯包含所有條目的表的命令。
foreach ($order as $ordercommout) {
$orderID = $ordercommout->ID;
$orderDateComp = strtotime($ordercommout->get_date_completed());
// echo $orderDateComp;
if($starttimeSTR < $orderDateComp && $endtimeSTR > $orderDateComp){
$affID = get_post_meta($orderID, "_coupon_codes_CCAFF_Aff_Affiliate_ID");
$affInfo = get_userdata($affID[0]);
$affName = $affInfo->user_login;
$order_subtotal = $ordercommout->total - $ordercommout->shipping_total - $ordercommout->total_tax;
$affcompctind = get_user_meta($affID[0], '_CCAFF_vendor_comm_pct');
$commissionamt = $order_subtotal*$affcompctind[0]*0.01;
$commpaidstatus1 = get_post_meta($orderID, "_coupon_codes_CCAFF_Comm_Status");
echo "<tr>";
echo "<td>" . esc_html($affName) . "</td>";
echo "<td>" . esc_html($orderID) . "</td>";
echo "<td>" . wc_price($commissionamt) . "</td>";
echo "<td>" . esc_html(date('m/d/Y', $orderDateComp)) . "</td>";
echo "<td>" . esc_html($commpaidstatus1[0]) . "</td>";
echo '<td><form method="post" action="" onsubmit="return confirm(' . "'" . 'Do you really want to delete Entry?' . "'" . ');">
<input type="hidden" id="delstart" name="delstart" value="' . esc_html($testdatestart) . '">
<input type="hidden" id="delend" name="delend" value="' . esc_html($testdateend) . '">
<input type="hidden" id="delcommtype" name="delcommtype" value="' . esc_html($testcommtype) . '">
<input type="hidden" id="delcommstatus" name="delcommstatus" value="' . esc_html($testcommstatus) . '">
<button type="submit" name="deleteItemCOMM" value="' . esc_html($orderID) . '"/>Delete</button></form></td>';
echo "</tr>";
}
}
所以問題是這段代碼有效。我的問題是我在 9 月初之前沒有收到任何訂單,我可以多次運行它,有時我會得到 9 月 12 日的資料。如果我再次運行它,我可能會到 9 月 8 日,等等。我的查詢似乎超時了,但我根本沒有等待它運行,輸出幾乎是即時的。有沒有辦法來解決這個問題?
uj5u.com熱心網友回復:
wc_get_orders有一個limit引數,與 WP_Query 一樣。
https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#parameters:
limit
接受整數:要檢索的最大結果數或 -1 表示無限制。
默認值:站點“posts_per_page”設定。
因此,除非您posts_per_page已經將無限(不太可能)設定為 -1,否則您應該limit => -1在此處明確指定查詢引數,以獲取所有帖子。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/526380.html
