I'm having an issue, I think it might be site/server related than code related as the db for this site is massive and this code worked perfectly before and i've never changed it. But what I am doing is grabbing all of the orders from a woocommerce store that have an "affiliate" associated with it. I do that with this code:
$order = wc_get_orders( array(
'status'=> 'wc-completed',
'meta_key' => '_coupon_codes_CCAFF_Aff_Affiliate_ID',
)
);
I then have a user form where the user enters a start date and end date and some other info for their query. (I can add the code in here for that if needed but trying to keep it short)
I then run a foreach loop though the orders where I echo out a table with all the entries.
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 class="ccformaff" 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" class="button button-primary" name="deleteItemCOMM" value="' . esc_html($orderID) . '"/>Delete</button></form></td>';
echo "</tr>";
}
}
So the thing is this code works. My issue is I'm not getting any orders before early September, I can run it multiple times and sometimes I get data to September 12th. If I run it again I might get up to September 8th, etc. It seems like my query is timing out but I'm not waiting long at all for it to run, the output is almost instant. Is there a way to fix this?
wc_get_orders
has alimit
parameter, same as WP_Query does.
https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#parameters:
limit
Accepts an integer: Maximum number of results to retrieve or -1 for unlimited.
Default: Site 'posts_per_page' setting.
So unless yourposts_per_page
was already set to -1 for unlimited (unlikely), you should explicitly specifylimit => -1
in your query parameters here, to get all posts.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.