Store results by attribut woocommerce

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Store results by attribut woocommerce

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #46479
    rvcomsoso
    rvcomsoso
    Participant

    Hi !
    I ‘ve installed and set up the plugin, but i’ve a conflict with my custom code on the results page : because I want to store the results by attributs (it’s a e-shop, and all products are store by attribute)
    so i create this shortcode to display results by attribut, it works fine, but when i active your plugin, the result are no longer sorted : I think my short codes are no longer taken into account ?
    So : it’s possible to store result like i want whith your plugin ? in the end i want do several tab for it, or to use your your search with my custom storage ?
    thanks a lot,

    see my custom code :
    <?php
    function custom_search_results_shortcode($atts) {
    ob_start();

    // Récupérer le terme de recherche
    $search_term = get_search_query();

    // Définir les attributs du shortcode
    $atts = shortcode_atts(
    array(
    ‘attribute’ => ”, // Attribut spécifié dans le shortcode
    ),
    $atts,
    ‘custom_search_results’
    );

    // Vérifier si l’attribut est spécifié
    if (!empty($atts[‘attribute’])) {
    // Paramètres de la requête
    $args = array(
    ‘s’ => $search_term, // Terme de recherche
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘pa_solution’, // Taxonomie
    ‘field’ => ‘slug’, // Champ (slug, name, term_id, or term_taxonomy_id)
    ‘terms’ => $atts[‘attribute’], // Terme de la taxonomie
    ),
    ),
    );

    // Créer une instance de WC_Product_Query
    $query = new WC_Product_Query($args);

    // Récupérer les produits
    $products = $query->get_products();

    // Vérifier si des produits ont été trouvés
    if ($products) {

    // Afficher la liste des produits
    foreach ($products as $product) {
    // Récupérer les informations du produit
    $product_id = $product->get_id();
    $product_title = $product->get_name();
    $product_link = get_permalink($product_id);

    // Afficher les informations du produit
    echo ‘<h2>’ . $product_title . ‘</h2>‘;
    }
    } else {
    echo ‘Aucun résultat trouvé‘;
    }
    } else {
    echo ‘<h2>Aucun attribut spécifié dans le shortcode</h2>’;
    }

    return ob_get_clean();
    }

    add_shortcode(‘custom_search_results’, ‘custom_search_results_shortcode’);

    And my shortcode like this : [custom_search_results attribute=”obione_produits”] [custom_search_results attribute=”obione_outils”] etc…
    thanks !

    #46490
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Okay – usually it is not the best idea to use custom queries with custom query arguments as the search query will override it in most cases.

    However you can make taxonomy term based exclusions and inclusions on the search settings – which should yield you the same output.

    Best,
    Ernest Marcinko

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


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.