I’m going to list two separate ways to achieve what you’re looking for:
Solution 1: Easier Approach:
This code snippet does the following:
_order_key
), Billing Last Name (_billing_last_name
), and Billing Email (_billing_email
).function custom_woocommerce_shop_order_search_fields( $search_fields ) {
// Remove default search fields
$search_fields = array();
// Add custom search fields: Order ID, Billing Last Name, and Billing Email
$search_fields[] = '_order_key'; // Order ID
$search_fields[] = '_billing_last_name'; // Billing Last Name
$search_fields[] = '_billing_email'; // Billing Email
return $search_fields;
}
add_filter( 'woocommerce_shop_order_search_fields', 'custom_woocommerce_shop_order_search_fields' );
Solution 2: Comprehensive Approach:
This code snippet combines everything into one. It will:
The JavaScript is added to the admin footer and will execute on the order search page, adding the dropdown dynamically.
This approach ensures that all modifications are contained within a single function and are executed in the correct context.
function custom_woocommerce_order_search_dropdown_and_custom_search() {
// Add JavaScript to insert the dropdown
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var dropdownHtml = '<select name="search_by" id="search_by" style="margin-right: 8px;">' +
'<option value="order_id">Order ID</option>' +
'<option value="email">Email</option>' +
'</select>';
$(dropdownHtml).insertBefore('#post-search-input');
});
</script>
<?php
// Modify the search query based on the selected option in the dropdown
add_filter( 'woocommerce_shop_order_search_fields', function ( $search_fields ) {
if ( isset( $_GET['search_by'] ) && 'email' === $_GET['search_by'] ) {
$search_fields = array('_billing_email'); // Search by Billing Email
} elseif ( isset( $_GET['search_by'] ) && 'order_id' === $_GET['search_by'] ) {
$search_fields = array('_order_key'); // Search by Order ID
}
return $search_fields;
}, 10, 2 );
}
add_action( 'admin_footer', 'custom_woocommerce_order_search_dropdown_and_custom_search' );
As always, testing on a staging environment first is highly recommended.
After adding either of these two solutions to your functions.php
file, your WooCommerce order search should only look through these specified fields, which could potentially speed up the search process.
Finish: 5.29 s DOMContentLoaded: 215 ms Load: 341?ms
The target value should be 2 to 3 sec. But for which one? The first, Finish or the second, DOMContentLoaded?
Regards Loek
]]>after using 10web booster to optimize my site and make it fastest, the images of the products just disappear I don’t use another plugin to speed up my site (only 10web)
any suggestions ?
]]>Since a while a woocommerce webshop that I made loads extremely slow.
We looked for a solution by upgrading to a Managed WP hosting but with no result.
What’s particular is that the wordpress site is constantly spiking to 100% CPU and RAM usage. The hosting party tried helping us and even upgraded the hosting package, but still the website kept using 100% of all resources (cpu & RAM).
Since the hosting party can’t seem to find any solution or cause, I am quite desperate right now. If someone knows a way to diagnose or solve this issue it would help a lot!
Thanks for all the help in advance!
Kind regards,
Julius
My website is super slow on normal mode, but works fine on incognito. Please help!
I have:
1. Updated all plugins and PHP.
2. Looked at the waterfall view, and nothing seems mayor.
3. Downloaded a developer plugin which showed which plugins took most time, and deleted those.
4. I have two other websites with the same theme, that works fast enough
5. I have called my website host, and they say it is nothing wrong with the server, which is the same host as for my other two, fast websites.
6. Tried everything on PageSpeed insights, but the higher number PageSpeed gives me the slower the website is in real time.
All I can see is that it seems to be a long (often over 10 seconds) wait until the pages actually starts loading, which then takes about 2 seconds. When I have loaded it once it starts going fast.
What can I do?
]]>