Toutes mes réponses sur les forums

Affichage de 1 message (sur 1 au total)
  • Auteur
    Messages
  • #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; »> * @see https://docs.woocommerce.com/document/template-structure/</span&gt;
    <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
    vpsa2
Affichage de 1 message (sur 1 au total)