Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Can Search adhere to menu visibility rules or some other visibility logic? › Reply To: Can Search adhere to menu visibility rules or some other visibility logic?
August 9, 2023 at 9:55 pm
#45017
Keymaster
Thanks! That helps a lot. Based on their API I have made a custom code, which may do the trick. Unfortunately I have not been able to test it yet.
Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter('asp_results', 'asp_results_remove_restricted_woo', 10, 1);
function asp_results_remove_restricted_woo($results) {
foreach ( $results as $k => &$r ) {
if ( isset($r->post_type) && $r->post_type == 'product' ) {
if ( !WC_Catalog_Restrictions_Filters::instance()->user_can_view_price( wc_get_product($r->id) ) ) {
unset($results[$k]);
}
}
}
return $results;
}