Add search box to My Account > Orders page
-
Hi,
I am trying to add a search option to the My Account > Orders page, where I would like users to be able to search for products they have bought by the product name. So far I have been unsuccessful – this is my current code:
<?php
echo’
<form method=”post” action=””>
<label>Search an Order ID</label><br>
<input type=”text” name=”searchTerm” value=””>
<input type=”submit” name=”submit” value=”Submit”/>
</form>’;
?>AND THEN IN FUNCTIONS.PHP:
add_filter( ‘woocommerce_my_account_my_orders_query’, ‘search_orders_by_name’, 20, 1 );
function search_orders_by_name( $args ){
if( isset($_POST[‘searchTerm’]) ){
$args[‘post__in’] = array($_POST[‘searchTerm’]);
}
return $args;I modified this code from someone who was looking to search by Order ID, but so far cannot get it to work. I would appreciate your help on the matter.
Thank you.
- The topic ‘Add search box to My Account > Orders page’ is closed to new replies.