Include Atributes in search

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Include Atributes in search

This topic contains 20 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 10 months ago.

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #13408
    fespigado
    fespigado
    Participant

    Sorry Ernest,
    but still looking for products in stock 0 searches.

    I´ve add added 1 more condition but it does not work.

    **********************************************************

    add_filter( ‘asp_results’, ‘asp_stock_to_content’, 1, 1 );

    function asp_stock_to_content( $results ) {
    $custom_field = “_stock”;

    foreach ($results as $k=>$v) {
    if ($v->content_type != “pagepost” || $v->post_type != “product”)
    continue;
    if ( function_exists(‘get_field’) )
    $meta_value = get_field( $v->id, $custom_field, true ); // ACF support
    else
    $meta_value = get_post_meta( $v->id, $custom_field, true );
    // Modify the post title to add the meta value
    if ( !empty($meta_value) || $meta_value <=0)
    $results[$k]->content .= ‘<br>Stock: ‘ . intval($meta_value) . ‘‘;
    }

    return $results;
    }

    Attachments:
    You must be logged in to view attached files.
    #13411
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Thank you very much for your offer and your kind words, I’m working alone so I’m completely overloaded with work for months. For WordPress related work I recommend wpkraken.io – it’s a fairly new service, by a team of codecanyon/themeforest authors, specialized in WordPress. In case you want to outsorce some customizations, they might worth asking.

    As for the code
    That code does no exclusions whatsoever, it’s only a visual ‘fix’ for rounding up the values. But, there is a way to check the stock status of the products (stored in a different custom field), and exclude them, check on this knowledge-base article: Showing in-stock products only

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #13424
    fespigado
    fespigado
    Participant

    Hi,

    sorry for my bad english.
    What I mean is that the stock does not appear but the product should appear.

    #13426
    fespigado
    fespigado
    Participant

    Hi Ernest,
    thanks for the information.
    The project I’m talking about is not on the wordpress platform.
    It’s an adhoc project.

    #13554
    fespigado
    fespigado
    Participant

    As promised, I share the code to show the stock in the search results if it is greater than 0. thanks for your help

    add_filter( ‘asp_results’, ‘asp_stock_to_content’, 1, 1 );

    function asp_stock_to_content( $results ) {
    $custom_field = “_stock”;

    foreach ($results as $k=>$v) {
    if ($v->content_type != “pagepost” || $v->post_type != “product”)
    continue;
    if ( function_exists(‘get_field’) )
    $meta_value = get_field( $v->id, $custom_field, true ); // ACF support
    else
    $meta_value = get_post_meta( $v->id, $custom_field, true );
    // Modify the post title to add the meta value

    if ( $meta_value > 0)
    $results[$k]->content .= ‘<br>Stock: ‘ . intval($meta_value) . ‘‘;
    else
    continue;
    }

    return $results;
    }

    #13577
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thank you very much!

    I think I might have another solution as well, altough I’m not sure if it works in all cases. I have placed it into this knowledge base article: https://wp-dreams.com/knowledge-base/woocommerce-showing-products-in-stock-only/

    ..the difference is that his one will completely remove the products if not in stock from the results.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 6 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic.