Woocommerce multisite global search premium integration
Question
Im trying to integrate Global Search Premium plugin (link to plugin) to my site, but some errors occurs! This is the original PHP Function to mod, someone can help me to integrate?
PS When i contacted seller answear with this guide, no other kind of support!!!
public function ajax_suggestions() {
if( apply_filters('basel_search_by_sku', basel_get_opt('search_by_sku') ) && basel_woocommerce_installed() ) {
add_filter('posts_search', array( $this, 'product_ajax_search_sku'), 10);
}
$allowed_types = array( 'post', 'product', 'portfolio' );
$post_type = 'product';
$query_args = array(
'posts_per_page' => 5,
'post_status' => 'publish',
'post_type' => $post_type,
'no_found_rows' => 1,
);
if ( ! empty( $_REQUEST['post_type'] ) && in_array( $_REQUEST['post_type'], $allowed_types ) ) {
$post_type = strip_tags( $_REQUEST['post_type'] );
$query_args['post_type'] = $post_type;
}
if ( $post_type == 'product' && basel_woocommerce_installed() ) {
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
$query_args['tax_query'][] = array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => $product_visibility_term_ids['exclude-from-search'],
'operator' => 'NOT IN',
);
if ( ! empty( $_REQUEST['product_cat'] ) ) {
$query_args['product_cat'] = strip_tags( $_REQUEST['product_cat'] );
}
}
if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && $post_type == 'product' ) {
$query_args['meta_query'][] = array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => 'NOT IN' );
}
if ( ! empty( $_REQUEST['query'] ) ) {
$query_args['s'] = sanitize_text_field( $_REQUEST['query'] );
}
if ( ! empty( $_REQUEST['number'] ) ) {
$query_args['posts_per_page'] = (int) $_REQUEST['number'];
}
$results = new WP_Query( apply_filters( 'basel_ajax_search_args', $query_args ) );
if ( basel_get_opt( 'relevanssi_search' ) && function_exists( 'relevanssi_do_query' ) ) {
relevanssi_do_query( $results );
}
$suggestions = array();
if ( $results->have_posts() ) {
if ( $post_type == 'product' && basel_woocommerce_installed() ) {
$factory = new WC_Product_Factory();
}
while ( $results->have_posts() ) {
$results->the_post();
if ( $post_type == 'product' && basel_woocommerce_installed() ) {
$product = $factory->get_product( get_the_ID() );
$suggestions[] = array(
'value' => get_the_title(),
'permalink' => get_the_permalink(),
'price' => $product->get_price_html(),
'thumbnail' => $product->get_image(),
'sku' => $product->get_sku() ? esc_html__( 'SKU:', 'basel' ) . ' ' . $product->get_sku() : '',
);
} else {
$suggestions[] = array(
'value' => get_the_title(),
'permalink' => get_the_permalink(),
'thumbnail' => get_the_post_thumbnail( null, 'medium', '' ),
);
}
}
wp_reset_postdata();
} else {
$suggestions[] = array(
'value' => ( $post_type == 'product' ) ? esc_html__( 'No products found', 'basel' ) : esc_html__( 'No posts found', 'basel' ),
'no_found' => true,
'permalink' => ''
);
}
echo json_encode( array(
'suggestions' => $suggestions
) );
die();
}
0
globals, search, woocommerce
7 months
0 Answers
97 views
0
Leave an answer
You must login or register to add a new answer .