Hello there and wish you all good month. I'm having an issue while I try to fetch products from WooCommerce using my search results (I'm trying to fetch them through my custom "searcher"). The thing is my searcher works but it only brings up a white screen and the name of the product. I want the product to show as it would be shown in a regular Woo Commerce store, with styles and everything as if I was searching it category wise or with any other parameter (like the plugins out there).
In order to help, this is my code so far :
functions.php:
function search_tickets_shortcode() {
ob_start();
get_template_part('tickets', 'search');
return ob_get_clean();
}
add_shortcode( 'ticket_searcher', 'search_tickets_shortcode' );
add_action('init','wpse_load_custom_search_template');
function wpse_load_custom_search_template(){
if( isset($_REQUEST['search']) == 'tickets' ) {
require('advanced-search-template.php');
die();
}
}
advanced-search-template.php:
<ul class="products">
<?php
$params = array('posts_per_page' => 5,
'post_type' => 'product'); // (1)
$wc_query = new WP_Query($params);
// Get data from URL into variables
$_strprt = $_GET['startingport'] != '' ? $_GET['startingport'] : '';
$_endprt = $_GET['endingport'] != '' ? $_GET['endingport'] : '';
// Start the Query
$v_args = array(
'post_type' => 'product', // your CPT
//'s' => $_strprt, // looks into everything with the keyword from your 'name field'
'meta_query' => array(
array(
'key' => '_sku', // assumed your meta_key is 'car_model'
'value' => $_strprt,
'compare' => 'LIKE', // finds models that matches 'model' from the select field
),
)
);
$vehicleSearchQuery = new WP_Query( $v_args );
// Open this line to Debug what's query WP has just run
// var_dump($vehicleSearchQuery->request);
// Show the results
if( $vehicleSearchQuery->have_posts() ) :
while( $vehicleSearchQuery->have_posts() ) : $vehicleSearchQuery->the_post();
the_title(); // Assumed your cars' names are stored as a CPT post title
endwhile;
else :
_e( 'Sorry, nothing matched your search criteria', 'textdomain' );
endif;
wp_reset_postdata();
?>
</ul>
And the form that I utilize for the searcher from tickets-search.php:
<form method="get" id="tickets-search" role="search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class ="row aligned">
<h3><?php _e( 'Tickets Search', 'textdomain' ); ?></h3>
<!-- PASSING THIS TO TRIGGER THE ADVANCED SEARCH RESULT PAGE FROM functions.php -->
<input type="hidden" name="search" value="tickets">
<label for="startingport" class="" required><?php _e( 'From: ', 'textdomain' ); ?></label><br>
<select name="startingport" id="startingport" required>
<option value=""><?php _e( 'From:', 'textdomain' ); ?></option>
<option value="Ancona"><?php _e( 'Ancona', 'textdomain' ); ?></option>
<option value="Igoumenitsa"><?php _e( 'Igoumenitsa', 'textdomain' ); ?></option>
</select><br><br>
<label for="endingport" class=""><?php _e( 'To: ', 'textdomain' ); ?></label><br>
<select name="endingport" id="endingport" required>
<option value=""><?php _e( 'To:', 'textdomain' ); ?></option>
<option value="IgoumenitsaR"><?php _e( 'AnconaR', 'textdomain' ); ?></option>
<option value="AnconaR"><?php _e( 'IgoumenitsaR', 'textdomain' ); ?></option>
</select>
<br><br>
<label for="datepickah">Choose date</label><br>
<input type="text" name="date" id="datepickah" required />
<br><br>
<div class="subm">
<input type="submit" id="searchsubmit" value="tickets" />
</div>
</div>
</form>
How can I achieve proper front-end "Products page" instead of just bringing the names of the products itself in a white background? I'm a newbie in PHP so any kind of help would be greatly appreciated. Thank you in advance!
PS:
Tried to find a plugin to achieve something like this but can't see any that suits my case. I also browsed a lot of questions posted here but can't seem to find also more help regarding the problem.