Hi @agenziae20
I have prepared a code snippet for you that allows searching only the vendor’s product on the vendor archive page.
// Check if we are in vendor store page and return author ID
function fibosearch_get_product_author() {
global $wp_query;
if ( ! isset( $wp_query->query['store'] ) || empty ( $wp_query->query['store'] ) ) {
return false;
}
$product_id = isset( $wp_query->posts ) ? $wp_query->posts[0]->ID : false;
$author = isset( $product_id ) ? get_post_field( 'post_author', $product_id ) : false;
return $author;
}
// Add author input to FiboSearch
add_action( 'dgwt/wcas/form', function () {
$author = fibosearch_get_product_author();
if ( ! empty( $author ) ) {
printf( '<input type="hidden" name="author" value="%d"/>', esc_attr( $author ) );
}
} );
// Pass author ID to FiboSearch params
add_filter( 'dgwt/wcas/scripts/custom_params', function ( $params ) {
$author = fibosearch_get_product_author();
$params['author'] = $author;
return $params;
} );
// Try to read the author ID and push to query args
add_filter( 'dgwt/wcas/search_query/args', function( $args ) {
if ( isset( $_REQUEST['author'] ) && ! empty( $_REQUEST['author'] ) ) {
$args['author'] = absint( wp_unslash( $_REQUEST['author'] ) );
}
return $args;
} );
Before taking any actions, please make a full backup of your website (including the database).
I recommend that you test this code on a test environment, e.g. staging.
Check how to easily create a staging site for WordPress.
You have two ways to add this code to your theme:
Open the functions.php in your child theme and add the code at the end.
or install the Code Snippets plugin and apply this code as a snippet.
Regards,
Kris