Disable Search on front end for single page
-
Hi Team,
Jamie here from WC Vendors Marketplace. I’ve built an integration with your plugin to provide support for EAN within WC Vendors. The issue our users are facing is that due to how we’ve built our dashboard, the ‘s’ query var is used for enabling search in our front end vendor dashboard for products. This results in EAN for WooCommerce filtering our products’ table to remove any products that don’t have an EAN added. Now we can disable frontend search in your settings and this fixes the issue for our dashboard, but then removes the ability to search by EAN on the front end.
I have attempted to modify our plugin to use ‘s’ query var conditionally, but this provides inconsistent results on our dashboard.
Would you be able to add a filter to your search method in the Alg_WC_EAN_Search class so that we can disable the search method on our dashboard page? I tested this by creating a filter called alg_wc_ean_search in the initial check at the top of the search function.
function search( $wp_query ) { global $wpdb; if ( ! isset( $wp_query->query['s'] ) || ! isset( $wp_query->query['post_type'] ) || 'product' != $wp_query->query['post_type'] || apply_filters( 'alg_wc_ean_search', false ) ) { return; } WC_Vendors::log( $wp_query ); $key = alg_wc_ean()->core->ean_key; $posts = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='{$key}' AND meta_value LIKE %s;", esc_sql( '%' . $wp_query->query['s'] . '%' ) ) ); if ( ! $posts ) { return; } unset( $wp_query->query['s'] ); unset( $wp_query->query_vars['s'] ); $wp_query->query['post__in'] = array(); foreach ( $posts as $id ) { if ( ( $post = get_post( $id ) ) ) { if ( $post->post_type == 'product_variation' ) { $wp_query->query['post__in'][] = $post->post_parent; $wp_query->query_vars['post__in'][] = $post->post_parent; } else { $wp_query->query_vars['post__in'][] = $post->ID; } } } }
Thanks in advance,
Jamie
- The topic ‘Disable Search on front end for single page’ is closed to new replies.