Woocommerce: Changer les variations sélectionner la valeur par défaut?
-
-
Vous souhaitezmodifier la règle de style appliquée au sélecteur ou vous souhaitezmodifier le sélecteur lui-même?Lepremierest hors sujetpar la [faq] comme étant unepure question CSS.You want to change the style rule applied to the selector, or you want to change the selector itself? The first is off-topic per the [faq] as being a pure CSS question.
- 0
- 2013-05-17
- s_ha_dum
-
Vérifiezmes commentaires à la réponse de Daniels :)Check my comments to Daniels answer :)
- 0
- 2013-05-17
- McKeene
-
3 réponses
- votes
-
- 2014-05-16
Si,commemoi,vous souhaitez avoir une option de variationpar défaut sélectionnée sans avoir àparcourir chaqueproduitet à sélectionner une valeurpar défaut via l'administrateur,vous devezmodifier lefichier
variable.php
quiest situé danswoocommerce/templates/single-product/add-to-cart/variable.php
(veuillezne pasmodifier lefichier WooCommerce Plugin - copiez-leplutôt dans votre répertoire Thèmes selon lesmeilleurespratiques).La cléiciest la dernière condition
else
à la ligne 35. Celle-ci détermine la valeur de variationpar défaut. Modifiez simplement:$selected_value = '';
... à ...
$selected_value = $options[0];
Cela définira la valeurpar défaut comme étant lepremier élément dutableau des variantes deproduit défini dans lebackend. De cettefaçon,votrebouton Ajouter aupanieresttoujours affichépar défautet l'utilisateur atoujours lapossibilité de sélectionner une autre variante s'il le souhaite.
Pourquoi cen'estpas dans lenoyau de WooCommerce,je ne saispas.
( Remarque cetteméthodepermettoujours à l'administrateur de définir une valeur de variationpar défaut spécifique àpartir de WPAdmin qui remplacera la valeurpar défaut définie à l'aide demon code ci-dessus)
If like me you'd like to have a default variation option selected without having to go through every Product and select a default via the admin then you need to alter the
variable.php
file which is located atwoocommerce/templates/single-product/add-to-cart/variable.php
(please do not alter the WooCommerce Plugin file - rather copy it to your Themes directory as per best practice).The key here is the final
else
condition on line 35. This which determines what the default variation value will be. Simply alter:$selected_value = '';
...to...
$selected_value = $options[0];
This will set the default value to be the first item in the array of product variations defined in the backend. That way your Add to Cart button is always shown by default and the user still has the ability to select another variation if they wish.
Why this isn't in WooCommerce core I don't know.
(Note this method still allows the admin to set a specific default variation value from the WPAdmin which will overide the default which gets set using my code above)
-
Ceciestproblématique lorsque vous avez du stocket que lapremière optionn'est PASen stock.Cela déclenchera une alerte disant "Désolé,aucunproduitne correspond à votre sélection ...".This is problematic when you have stock, and the first option is NOT in stock. This will trigger an alert saying 'Sorry, no products matched your selection...'.
- 1
- 2015-03-11
- jetlej
-
- 2013-05-17
Sur lapage d'édition duproduitpour leproduit variable,cliquez sur l'onglet "Variations". Unefois que vous avez configuré les variationspour la couleur,vouspouvez définir une "sélectionpar défaut"en bas: http://cld.wthms.co/7LIv
Ce sera l'optionpar défaut sélectionnée lorsqu'un client visite lapage (sielleesten stock). Exemple: http://cld.wthms.co/YQFO
On the Product Edit page for the variable product, click on the "Variations" tab. Once you setup variations for the Colour you can set a "Default selection" at the bottom: http://cld.wthms.co/7LIv
This will be the default option selected when a customer visits the page (if it is in stock). Example: http://cld.wthms.co/YQFO
-
Je veuxtoujours une valeurpar défaut,maisje dois changer letexte de "Choisiret option" à "sélectionner lataille".Sur lapage,vous devez choisir unetaille avant que lebouton d'achatn'apparaisse.S'il utilise unetaillepar défaut,cettefonction disparaîtrait.I still want a default value, but i need to change the text from "Choose and option" to "select size". On the page you have to choose a size before the buy button actually appears. If it uses a size as the default, this function would disappear.
- 0
- 2013-05-17
- McKeene
-
- 2014-03-25
Je sais qu'ilest unpeutard à ce stade,maisjuste au cas où quelqu'un d'autre rencontrerait ceproblème.Cela devrait vouspermettre demodifier letexte de la valeurpar défaut.
Copiezet collez ceci dans votrefichierfunctions.php dethèmes.Cen'estpeut-êtrepas lameilleurefaçon deprocéder,mais cela atrèsbien fonctionnépourmoi.
/* Change Woocommerce Default Value Text */ add_filter('gettext', 'choose_option'); add_filter('ngettext', 'choose_option'); function choose_option($translated) { $translated = str_ireplace('Choose an option', 'Select Size', $translated); return $translated; }
REMARQUE: Celamodifiera letexte de la valeurpar défaut sur l'ensemble du site.Juste un avertissement!
I know it's a little late at this point but just in case anyone else runs into this problem. This should allow you to change the default value text.
Copy and paste this into your themes functions.php file. It may not be the best way to do it but it worked great for me.
/* Change Woocommerce Default Value Text */ add_filter('gettext', 'choose_option'); add_filter('ngettext', 'choose_option'); function choose_option($translated) { $translated = str_ireplace('Choose an option', 'Select Size', $translated); return $translated; }
NOTE: This will change the default value text throughout the entire site. Just a heads up!
Surmon site ,je souhaitemodifier la valeurpar défaut du sélecteurqui apparaît,lorsque différentes variationsexistent.Si quelqu'unpeutme donner uneidée de commentet où celaestfait,ce seraittrès apprécié!