WooFrance Dépannage et support WordPress WooCommerce Forums Forum de Support WooCommerce Paramétrage ordre d'affichage des produits liés

Étiqueté : 

5 sujets de 1 à 5 (sur un total de 5)
  • Auteur
    Messages
  • #5772
    Dulongcourty
    Participant
    Points: 43 pts
    Membre 2 étoiles

    Bonjour à tous,

    J’ai un petit souci que je n’arrive à résoudre et sollicite donc votre aide

    Sur mes pages produits, dans la description courte, j’ai mis un shortcode qui me permet d’afficher les produits liés , que je paramètre pour chaque produit dans woocommerce.

    Le hic, c’est que je n’ai aucun contrôle sur l’ordre d’affichage, et souhaiterai toucher au code pour lui dire qu’il classe les produits dans l’ordre d’affichage (Selon UGS), est ce que vous avez une idée du fichier que je pourrai modifier pour avoir la possibilité de faire ça ? Merci d’avance, et bonne après midi 😉

    depanagewp
    #5905
    Mathieu
    Participant
    Points: 1,315 pts
    Membre 2 étoiles

    Le filtre de tri que j’ai vu ne permet pas de filtrer par U.G.S. donc je pense que la meilleure solution serait de faire le tri directement dans le fichier single-product/up-sells.php

    le tri peut se faire avec ce code :

    usort($upsells, function ($p1, $p2) {
        return strnatcasecmp($p1->get_sku(), $p2->get_sku());
    });

    Développeur PHP et WordPress En Alsace dans l'annuaire des prestataires WordPress et WooCommerce
    Création d'extensions pour WordPress et WooCommerce - Personnalisation d'extensions existantes
    🔶 Si vous appréciez mon aide, vous pouvez me faire un don de n'importe quel montant en cliquant ici.

    depanagewp
    #40906
    Dulongcourty
    Participant
    Points: 43 pts
    Membre 2 étoiles

    Bonjour tout le monde,

    Excusez moi pour le délai de réponse, et merci pour ta réponse Mathieu, en revanche, sais-tu ou je pourrai mettre ce bout de code  dans le fichier en question ? Je n’y connais rien en php donc je n’ai pas envie de faire de betises

    depanagewp
    #41077
    Mathieu
    Participant
    Points: 1,315 pts
    Membre 2 étoiles

    si le fichier single-product/up-sells.php existe déjà dans le répertoire “woocommerce” du thème, c’est ce fichier qui peut être modifié (si le thème n’est plus mis à jour)

    et s’il n’existe pas, il faut d’abord le récupérer dans les fichiers de l’extension woocommerce, répertoire “templates” et le copier dans le thème.

    Développeur PHP et WordPress En Alsace dans l'annuaire des prestataires WordPress et WooCommerce
    Création d'extensions pour WordPress et WooCommerce - Personnalisation d'extensions existantes
    🔶 Si vous appréciez mon aide, vous pouvez me faire un don de n'importe quel montant en cliquant ici.

    depanagewp
    #196327
    annasd55
    Participant
    Points: 13 pts

    Bonjour,

    En faisant une recherche pour trouver comment ajouter un tri par UGS (SKU) aux paramètres de WooCommerce, je suis arrivée sur votre échange. J’ai trouvé le fichier à modifier pour ajouter le code ci-haut mentionné, mais étant encore débutante en programmation, j’aimerais vous demander cette question… Sur laquelle de ces lignes devrais-je ajouter le code

    <span style=”background-color: #f9f9f9; color: #191919; font-family: Inconsolata, Consolas, Monaco, ‘Lucida Console’, monospace; font-size: 15px; white-space: pre;”>usort($upsells, function ($p1, $p2) {</span>

    <span style=”color: #191919; font-family: Inconsolata, Consolas, Monaco, ‘Lucida Console’, monospace; font-size: 15px; white-space: pre; background-color: #f9f9f9;”> return strnatcasecmp($p1->get_sku(), $p2->get_sku()); });</span>

    si le fichier se présente comme ceci:

    <span style=”color: #e00000; font-weight: bold;”><?php</span>
    <span style=”color: #008000;”>/**</span>
    <span style=”color: #008000;”> * Single Product Up-Sells</span>
    <span style=”color: #008000;”> *</span>
    <span style=”color: #008000;”> * This template can be overridden by copying it to yourtheme/woocommerce/single-product/up-sells.php.</span>
    <span style=”color: #008000;”> *</span>
    <span style=”color: #008000;”> * HOWEVER, on occasion WooCommerce will need to update template files and you</span>
    <span style=”color: #008000;”> * (the theme developer) will need to copy the new files to your theme to</span>
    <span style=”color: #008000;”> * maintain compatibility. We try to do this as little as possible, but it does</span>
    <span style=”color: #008000;”> * happen. When this occurs the version of the template file will be bumped and</span>
    <span style=”color: #008000;”> * the readme will list any important changes.</span>
    <span style=”color: #008000;”> *</span>
    <span style=”color: #008000;”> * @package WooCommerce\Templates</span>
    <span style=”color: #008000;”> * @version 3.0.0</span>
    <span style=”color: #008000;”> */</span>
    <span style=”color: #0000ff;”>if</span> ( ! defined( <span style=”color: #a31515;”>’ABSPATH'</span> ) ) {
        <span style=”color: #0000ff;”>exit</span>;
    }
    <span style=”color: #0000ff;”>if</span> ( <span style=”color: #001188;”>$upsells</span> ) : <span style=”color: #e00000; font-weight: bold;”>?></span>
        <span style=”color: #383838;”><</span><span style=”color: #800000;”>section</span> <span style=”color: #ff0000;”>class</span>=<span style=”color: #0451a5;”>”up-sells upsells products”</span><span style=”color: #383838;”>></span>
            <span style=”color: #e00000; font-weight: bold;”><?php</span>
            <span style=”color: #001188;”>$heading</span> = apply_filters( <span style=”color: #a31515;”>’woocommerce_product_upsells_products_heading'</span>, __( <span style=”color: #a31515;”>’You may also like&hellip;'</span>, <span style=”color: #a31515;”>’woocommerce'</span> ) );
            <span style=”color: #0000ff;”>if</span> ( <span style=”color: #001188;”>$heading</span> ) :
                <span style=”color: #e00000; font-weight: bold;”>?></span>
                <span style=”color: #383838;”><</span><span style=”color: #800000;”>h2</span><span style=”color: #383838;”>></span><span style=”color: #e00000; font-weight: bold;”><?php</span> <span style=”color: #0000ff;”>echo</span> esc_html( <span style=”color: #001188;”>$heading</span> ); <span style=”color: #e00000; font-weight: bold;”>?></span><span style=”color: #383838;”></</span><span style=”color: #800000;”>h2</span><span style=”color: #383838;”>></span>
            <span style=”color: #e00000; font-weight: bold;”><?php</span> <span style=”color: #0000ff;”>endif</span>; <span style=”color: #e00000; font-weight: bold;”>?></span>
            <span style=”color: #e00000; font-weight: bold;”><?php</span> woocommerce_product_loop_start(); <span style=”color: #e00000; font-weight: bold;”>?></span>
                <span style=”color: #e00000; font-weight: bold;”><?php</span> <span style=”color: #0000ff;”>foreach</span> ( <span style=”color: #001188;”>$upsells</span> <span style=”color: #0000ff;”>as</span> <span style=”color: #001188;”>$upsell</span> ) : <span style=”color: #e00000; font-weight: bold;”>?></span>
                    <span style=”color: #e00000; font-weight: bold;”><?php</span>
                    <span style=”color: #001188;”>$post_object</span> = get_post( <span style=”color: #001188;”>$upsell</span>->get_id() );
                    setup_postdata( <span style=”color: #4864aa;”>$GLOBALS</span>[<span style=”color: #a31515;”>’post'</span>] =& <span style=”color: #001188;”>$post_object</span> ); <span style=”color: #008000;”>// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found</span>
                    wc_get_template_part( <span style=”color: #a31515;”>’content'</span>, <span style=”color: #a31515;”>’product'</span> );
                    <span style=”color: #e00000; font-weight: bold;”>?></span>
                <span style=”color: #e00000; font-weight: bold;”><?php</span> <span style=”color: #0000ff;”>endforeach</span>; <span style=”color: #e00000; font-weight: bold;”>?></span>
            <span style=”color: #e00000; font-weight: bold;”><?php</span> woocommerce_product_loop_end(); <span style=”color: #e00000; font-weight: bold;”>?></span>
        <span style=”color: #383838;”></</span><span style=”color: #800000;”>section</span><span style=”color: #383838;”>></span>
        <span style=”color: #e00000; font-weight: bold;”><?php</span>
    <span style=”color: #0000ff;”>endif</span>;
    wp_reset_postdata();
    Merci à l’avance pour votre aide!
    depanagewp
5 sujets de 1 à 5 (sur un total de 5)
  • Vous devez être connecté pour répondre à ce sujet.